Python Nose Import Error
You've got an __init__.py
in your top level directory. That makes it a package. If you remove it, your nosetests
should work.
If you don't remove it, you'll have to change your import
to import dir.foo
, where dir
is the name of your directory.
Are you in a virtualenv? In my case, nosetests
was the one in /usr/bin/nosetests
, which was using /usr/bin/python
. The packages in the virtualenv definitely won't be in the system path. The following fixed this:
source myvirtualenv/activate
pip install nose
which nosetests
/home/me/myvirtualenv/bin/nosetests
To those of you finding this question later on: I get the import error if I don't have an __init__.py
file in my tests directory.
My directory structure was like this:
./tests/
./test_some_random_stuff.py
If I ran nosetests:
nosetests -w tests
It would give the ImportError
that everyone else is seeing. If I add a blank __init__.py
file it works just fine:
./tests/
./__init__.py
./test_some_random_stuff.py