20

I installed Nose on a Mac OSX 10.10.5 with Python2.7.9 using easy_install. The installation appeared to be successful:

Collecting nose
  Downloading nose-1.3.7-py2-none-any.whl (154kB)
    100% |████████████████████████████████| 155kB 2.3MB/s 
Installing collected packages: nose
Successfully installed nose-1.3.7

But now, when I try even basic stuff with nosetests on the command line, like nosetests -h or which nosetests I just get:

bash: nosetests: command not found

I have tried uninstalling, reinstalling using pip, tried installing with sudo and then running sudo nostests in the directories with tests scripts as other posts have suggested, but nothing seems to work.

The original purpose for installing was to use nose to run some basic tests with tests scripts I had written for these simple web.py apps. But nothing works, just keep getting the command not found response.

What's strange is that, when I open up the Python interpreter in Terminal, and do something like:

import nose 
nose.main()

I get the expected result of:

.
----------------------------------------------------------------------
Ran 1 test in 0.135s

OK

So clearly it's installed....somewhere. Any suggestions for what the hell is going on here?

AdjunctProfessorFalcon
  • 1,790
  • 6
  • 26
  • 62

9 Answers9

30

There are lots of error occurred when using pip install packages on Mac OS. So I recommend you install nose using easy_install.

$ pip uninstall nose

$ sudo easy_install nose

Then you can try nosetests now :)

yolanda.ly
  • 311
  • 1
  • 3
  • 3
15

I had this exact issue on OS X EI Captain with Python 2.7.10.

First I installed nose using pip:

$sudo pip install nose 

which failed on the first attempt. Went through on the second attempt. But the nosetests command didn't work.

In order to fix this:

Step 1: Don't uninstall nose if it was installed already using pip as in my case.

Step 2:

$cd /usr/bin

$sudo easy_install nose 

Above command finds the nosetests script (which was installed by pip earlier) & sets it under /usr/local/bin

Step 3: Try nosetests

$nosetests

----------------------------------------------------------------------
Ran 0 tests in 0.047s

OK
mx0
  • 6,445
  • 12
  • 49
  • 54
Razikh
  • 173
  • 1
  • 6
12

On UNIX-like systems like OS X, the script should be in /usr/local/bin. Make sure that directory is in the PATH environment variable in the shell that you use.

If not, you can also locate it using find, e.g:

find / -type f -name 'nosetests*' -perm +111 -print -quit

This means; search for a file whose name starts with nosetests, which has execute permissions set. Print the path name and stop.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • Thanks for that command, it seems to have returned: `/Library/Frameworks/Python.framework/Versions/2.7/bin/nosetests ` Knowing that, how should I adjust my approach to using Nosetests command? – AdjunctProfessorFalcon Sep 13 '15 at 05:33
  • 3
    Add `/Library/Frameworks/Python.framework/Versions/2.7/bin/` to your `PATH`. How/where to do that depends on the shell you use. – Roland Smith Sep 13 '15 at 05:37
  • Thanks for the help! Is there a workaround so that when I'm in a project directory I don't have to use this long file path to use Nosetests? Would setting PYTHONPATH= to something when I'm in the directory work? – AdjunctProfessorFalcon Sep 13 '15 at 06:19
  • 2
    When you are calling `nosetests` from a shell, it has nothing to do with `PYTHONPATH`. But all shells that I know of use an environment variable called`PATH` that contains a list of directories separated by colons. Shells look in these directories for executables. Any executable file in one of those directories can be started by just calling it by its name. Where to set this environment variable differs per shell. Look at FILES section in the manual page for your shell. – Roland Smith Sep 13 '15 at 08:30
3

I found that going to

Library/usr/bin 

and running

sudo easy_install nose

it seems that sometimes it doesn't automatically install nose (and therefore nosetests functionality). Do the above lines, and you should be a-ok.

I wish i had a better explanation for why this happened, but i'm still pretty new, myself.

2

I had to use

Nosetest

or

python3 -m "nose"

Apparently this is the way Nosetest should be used in Python3. See also How to make nosetests use python3

Lorenz
  • 165
  • 1
  • 1
  • 10
0

First, can you run 'python' from the command line? nosetests should be in that same directory:

rich bin $ which python
/home/rich/anaconda/bin/python
rich bin $ which nosetests
/home/rich/anaconda/bin/nosetests

It should also be in the downloaded nose package:

rich bin $ find /home/rich/anaconda -name nosetests
/home/rich/anaconda/pkgs/nose-1.3.3-py27_0/bin/nosetests
/home/rich/anaconda/pkgs/nose-1.3.7-py27_0/bin/nosetests
/home/rich/anaconda/bin/nosetests
Rich L
  • 369
  • 3
  • 12
  • Yes, I can definitely run python from the command line. When I run `which python` I get: `/usr/local/bin/python` but as I mentioned in my post, I can't run `which nosetests` – AdjunctProfessorFalcon Sep 13 '15 at 05:25
0

From what I understand, everyone is moving to pytest - an actively-maintained testing framework.

It's not a solution to this problem, but it's likely the most-appropriate choice if you are still using nose.

Boris Yakubchik
  • 3,861
  • 3
  • 34
  • 41
0

I try to reinstall the pip, it doesn't work but lastly, when i use sudo ...it works

pip3 uninstall nose

sudo pip3 install nose

and

which nosetests

/usr/local/bin/nosetests

Community
  • 1
  • 1
0

This can also happen if you were running nose within a virtual environment, and that virtual environment has been deactivated. If this is the case, reactivate with source bin/activate.