Take the 2-minute tour ×

I am unable to use nose (nosetests) in a virtualenv project - it can't seem to find the packages installed in the virtualenv environment.

The odd thing is that i can set

test_suite = 'nose.collector'

in setup.py and run the tests just fine as

python setup.py test

but when running nosetests straight, there are all sorts of import errors.

I've tried it with both a system-wide installation of nose and a virtualenv nose package and no luck.

Any thoughts?


share|improve this question
On a related note, nose works fine "out of the box" on a different computer... so there's something wonky with the system I was having problems on. –  Ryan May 15 '09 at 17:07

8 Answers 8

up vote 25 down vote accepted

Are you able to run myenv/bin/python /usr/bin/nosetests? That should run Nose using the virtual environment's library set.

share|improve this answer
Yes indeed. That does work. Thank you! –  Ryan May 15 '09 at 17:06
If using with scripts that other developers will use, you can do python `which nosetests` –  bcoughlan May 15 '13 at 17:38
Try this alias nosetests='/usr/bin/env python $(which nosetests)' –  Necrolyte2 Nov 20 '13 at 14:04

You need to have a copy of nose installed in the virtual environment. In order to force installation of nose into the virtualenv, even though it is already installed in the global site-packages, run pip install with the -I flag:

(env1)$ pip install nose -I

From then on you can just run nosetests as usual.

share|improve this answer
It seems that one might have to refresh the virtualenv. Namely, which nosetests should point to an executable inside of the virtualenv. –  Ceasar Bautista Jul 16 '13 at 5:52
+1 This is what worked for me. Also, as Ceasar points out, I also had to refresh the virtualenv by running deactivate and then reactivating. –  Tom Oct 1 '13 at 16:31
this should be the accepted answer !!! –  tkoomzaaskz Feb 6 at 16:39
After you use this command, then deactivate, then workon ENV, it seems you can then use python `which nosetests` . –  oddshocks Oct 15 at 5:08

Here's what works for me:

$ virtualenv --no-site-packages env1
$ cd env1
$ source bin/activate            # makes "env1" environment active,
                                 # you will notice that the command prompt
                                 # now has the environment name in it.

(env1)$ easy_install nose        # install nose package into "env1"

I created a really basic package slither that had, in its setup.py, same test_suite attribute as you mentioned above. Then I placed the package source under env1/src.

If you looked inside env1/src, you'd see:

slither/slither/impl.py          # has some very silly code to be tested
slither/slither/tests.py         # has test-cases 

I can run the tests using test subcommand:

(env1)$ pushd src/slither
(env1)$ python setup.py test
# ... output elided ...
test_ctor (slither.tests.SnakeTests) ... ok
test_division_by_zero (slither.tests.SnakeTests) ... ok
Ran 2 tests in 0.009s
(env1)$ popd

Or, I can run the same tests with nosetests:

(env1)$ pushd src
(env1)$ nosetests slither/
Ran 2 tests in 0.007s
(env1)$ popd

Also note that nosetests can be picky about executables. You can pass --exe if you want it to discover tests in python modules that are executable.

share|improve this answer

I got a similar problem. The following workaround helped:

python `which nosetests` 

(instead of just nosestests)

share|improve this answer

In the same situation I needed to reload the virtualenv for the path to be correctly updated:

share|improve this answer

Perhaps this is a recent change, but for me, when I installed nosetests through pip, there was a nosetests executable installed in .virtualenvs/<env>/bin, which (unsurprisingly) operates correctly with the virtualenv.

share|improve this answer

You might have a nosetests that is installed somewhere else in your PATH with higher priority than the one installed in your virtualenv. A quick way to give the nose module and associated nosetests script installed in your current virtualenv top priority is to edit your PATH:

export PATH=/path/to/current/virtualenv/bin:$PATH
share|improve this answer

If all else fails, try installing nose in your venv, and/or run nosetests-2.7. I believe @andrea-zonca's answer has the same effect if your venv python is 2.7

share|improve this answer

Your Answer


