cannot import my util module
Looks like a package/pythonpath problem. The system need to know where to locale your modules. Do you have __init.py__
in my_app
and analytic
folder? The __init__.py
file mark directories on disk as Python package directories. And the structure should be like this
|- sentiment/
|- run.py
|- my_app/
|- __init__.py
|- analytic/
|- __init__.py
|- views.py
|- util. py
|- vect.pkl
then in your run.py
, try import with
import my_app.analytic.utils
or
from my_app.analytic.utils import <yourClassName>
for details of python package, check here. And be aware of namespace problem.
Rooco
Im a web developer, currently focusing on python web development with Flask micro framework (REST) and client side development with AngularJS
Updated on March 12, 2020Comments
-
Rooco about 4 years
I'm using
sklearn.externals.joblib
to persist a classifier model to the disk which in reality usespickle
module at lower level.I create a custom
CountVectorizer
class namedStemmedCountVectorizer
and saved it inutil.py
, then used it in the script for persisting the modelimport util from sklearn.externals import joblib vect = util.StemmedCountVectorizer(stop_words='english', ngram_range=(1,1)) bow = vect.fit_transform(sentences) joblib.dump(vect, 'vect.pkl')
This my project structure using Flask:
|- sentiment/ |- run.py |- my_app/ |- analytic/ |- views.py |- util. py |- vect.pkl
I run the app with
python run.py
and try to load the persisted object withjoblib.load
inviews.py
but it does not work, I imported theutil
module but I receive the error:ImportError: No module named util
can anybody give a solution to this? thanks