I am getting this stack trace when I start pyramid pserve:
% python $(which pserve) ../etc/development.ini
Traceback
I got this when I didn't type things right. I had
__init.py__
instead of
__init__.py
My usual trick is to simply print sys.path
in the actual context where the import problem happens. In your case it'd seem that the place for the print is in /home/hughdbrown/.local/bin/pserve
. Then check dirs & files in the places that path shows..
You do that by first having:
import sys
and in python 2 with print expression:
print sys.path
or in python 3 with the print function:
print(sys.path)
The PYTHONPATH
is not set properly. Export it using export PYTHONPATH=$PYTHONPATH:/path/to/your/modules
.
I met the same problem, and I try the pdb.set_trace() before the error line.
My problem is the package name duplicate with the module name, like:
test
├── __init__.py
├── a
│ ├── __init__.py
│ └── test.py
└── b
└── __init__.py
and at file a/__init__.py
, using from test.b import xxx
will cause ImportError: No module named b
.
I had the same problem, and I solved it by adding the following code to the top of the python file:
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
Number of repetitions of os.path.dirname
depends on where is the file located your project hierarchy. For instance, in my case the project root is three levels up.