Zubin
Zubin

Reputation: 403

Installing nose using pip, but bash doesn't recognize command on mac

I'm trying to install nose on my computer for the Learn Python the Hard Way tutorial, but can't seem to get it to work. I'm using pip to install:

$ pip install nose

And I get back:

Requirement already satisfied (use --upgrade to upgrade): nose in /usr/local/lib/python2.7/site-packages
Cleaning up...

However, when I run the command nosetests, I get:

-bash: nosetests: command not found

I'm thinking there's something wrong with my PATH, but honestly I have no idea. Any help would be greatly appreciated!

Upvotes: 35

Views: 48494

Answers (10)

Nathan Smith
Nathan Smith

Reputation: 681

Sorry for resurrecting an old thread, but I just want to point out that no one has mentioned activating the virtual environment. People are asking "Are you in the virtual environment?" but user2778157 seems to be confused on exactly what that means. I would like to clarify this and think it may actually be the source of the problem. (Sorry for the pun on source).

When you use pip install, you aren't installing to your host's system, but into the virtual environment. When you create a virtual environment, it will have a folder bin with a file activate in it. In order to activate the virtual environment, you need to do source PATH/TO/ACTIVATE. While your virtual environment is activated, your system will check your virtual environment for the program before checking the host, and this is where your pip packages should be.

The reason you don't use sudo pip install is because this will get the super user (who doesn't have the environment activated) to install the package, which will go to your host.

Upvotes: 2

Quang Nguyen
Quang Nguyen

Reputation: 2660

Setting PATH variable for 'nosetests' is required. Please use this one on your Terminal:

alias nosetests='/Library/Frameworks/Python.framework/Versions/2.7/bin/nosetests'

Good luck!

Upvotes: 1

Jimmy_Rw
Jimmy_Rw

Reputation: 1356

i had the same problem but this solved it.

  1. Install: nose2
  2. Then use: nose2 instead of nosetests to test program

Good Luck...!

Upvotes: 13

Dennis
Dennis

Reputation: 327

You can reinstall using apt-get -y install python-nose.

Upvotes: -1

Raphael
Raphael

Reputation: 201

I'm using OS X 10.11.1.

Do the following in the terminal:

  1. Move into directory ~/Python/2.7/site-packages/

  2. type sudo easy_install pip

  3. type sudo easy_install virtualenv

  4. type sudo easy_install nose

  5. type sudo easy_install distribute

  6. Follow the steps as instructed in the Learn Python The Hard Way book.

Upvotes: 6

Chris
Chris

Reputation: 934

I know this is an old thread but just in case someone else needs it:

I'm using OS X 10.9.3. After installing all of the packages 'cd' into the project directory as instructed in the book. Then type

sudo nosetests

Then you'll see what the 'learnpythonthehardway' author shows in the book and online.

Upvotes: -2

Tossrock
Tossrock

Reputation: 681

On OSX, using pip to install nose 1.3 installed nose to /usr/local/share/python/nosetests which isn't in the $PATH by default.

Upvotes: 2

Maxim Yefremov
Maxim Yefremov

Reputation: 14185

I got this problem until I setup nose with sudo:

sudo pip install nose

Upvotes: 14

7stud
7stud

Reputation: 48649

However, when I run the command nosetests,

Of course, how you ran that command and from what directory might be important.

I'm thinking there's something wrong with my PATH, but honestly I have no idea.

If you do:

$ echo $PATH

...you will be able to see all the directories in your path. Of course, you can add any directory you want to your PATH.

However, I recently installed nose on my mac, and I installed by hand:

.../Downloads$ tar xfvz nose-1.3.0
.../Downlaods$ cd nose-1.3.0
.../nose-1.3.0$ sudo python setup.py install

...and nosetests installed here:

$ which nosetests
/Library/Frameworks/Python.framework/Versions/2.7/bin/nosetests

And there is a nose directory in my site-packages directory as per usual, as well. So on my mac, nosetests installed in a directory outside the site-packages directory. It's possible that only newer versions of nose install the nosetests command. You might want to try:

$ pip install --upgrade nose

Upvotes: 1

user1971598
user1971598

Reputation:

pigging backing off of 7stud, you could do sudo find / -name nosetests and then append that to your PATH

(I'm sure that doing find off of / is a bit overkill, but I like that it goes over the entire OS)

Upvotes: 0

Related Questions