Import Error at celery launch
-
I have a folder structure like this:
- src -- \frontend --- \views ---- tasks.py -- \generator --- tasks.py
♪
frontend/views/tasks
I do:from generator import tasks
♪
When the folders start from the folderviews
Pyton says:ImportError: No module named generator
What's the reason for this mistake?
-
Parental Directory
generator
I have to besys.path
♪from generator import tasks
I was working in that case.Enough.
src
The directors will launch the path to PYTHONPATH automatically add:src$ python -m frontend.views.tasks
If you want to get out of other directors at the time of development, you can create
setup.py
For each package and to establish them:<top-package-dir>$ pip install -e .
Don't change your hands.
sys.path
In its code, it leads to surprises with invisible origin, for example, see. http://www.python.org/dev/peps/pep-0395/#traps-for-the-unwary ♪Some packages are automatically modified
sys.path
e.g.twisted
Use it. https://github.com/twisted/twisted/blob/ea2a2000a922f7269060ef9dd9a7db6cd4261ee0/bin/_preamble.py to make violets ofbin
Directors could not be installedtwisted
Find a package. But such practices are not encouraged, for example, Pypy had a similar violin in the past. https://bitbucket.org/pypy/pypy/src/a299cd0a893f/pypy/tool/autopath.py?at=default but now it's no longer used -- it's causing more problems than it does.Example of import problems: https://stackoverflow.com/q/14183541/4279