tags:

views:

35

answers:

2

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?

A: 

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.

Peter Farmer
A: 

Look for .pth files anywhere on the path. These files (e.g., easy-install.pth) can contain additional sys.path entries (one per line).

Ian Bicking