I'm seeing some additional items in sys.path
which 1) don't exist and 2) cause problems with imports (specifically with Nose
).
Basically, I've created a package (lets call it foo
) which I use in multiple projects. The project I'm working on at the moment can import everything from foo
without issue, but when I run Nose
I get import errors:
E
======================================================================
ERROR: Failure: ImportError (No module named foo)
----------------------------------------------------------------------
Traceback (most recent call last):
...
File "/path/to/my-project/file.py", line 6, in <module>
from foo import *
ImportError: No module named foo
----------------------------------------------------------------------
Ran 1 test in 0.004s
FAILED (errors=1)
When I spit out the path I get:
["/path/to/my-project/foo",
"/path/to/my-project/foo",
...,
"/usr/virtualenvs/my-project/lib/python2.6/site-packages/foo-py2.6.egg",
...]
/path/to/my-project/foo
doesn't exist. If I pop the first 2 entries off sys.path
everything works fine.
Can someone explain to me why those items are showing up when, really, the only one that should be in the list is the one installed into the virtualenv?
And how do I stop this from happening in the future? Is it something to do with the setup.py
in foo
?
Do you have anything in $PYTHONPATH
? This will put entries in sys.path even within a virtualenv enviroment.
Try unset PYTHONPATH
in bash (if you use bash) and then see what your sys.path
contains.
Look for .pth
files anywhere on the path. These files (eg, easy-install.pth
) can contain additional sys.path entries (one per line).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.