itenyh
itenyh

Reputation: 1939

pip: command not found

I encounter a problem when installing pip for python2.7. I downloaded the file get-pip.py, and install it successfully:

bogon:haha itensb$ python get-pip.py
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages
Cleaning up...

But when I run the command pip, I got:

-bash: pip: command not found

I think it is the PATH not set appropriatelly , But I new on Mac. I need your help , thanks!

Upvotes: 1

Views: 30516

Answers (4)

Python Basketball
Python Basketball

Reputation: 2370

to run the command, it works

sudo easy_install pip

Upvotes: 1

N.Lee
N.Lee

Reputation: 1036

Install python3 first, then use pip3 to install packages.

brew install python

python3 will be installed, and pip is shipped with it. To use pip to install some package, run the following

pip3 install package

Notice it's pip3 because you want to use python3.

My same answer here

Upvotes: 2

TheInitializer
TheInitializer

Reputation: 576

Use python -m pip. If you want the pip command check out @user3282276's answer.

Upvotes: 5

user3282276
user3282276

Reputation: 3804

Sounds like your PATH variable is not set to include the location that pip was installed to. On Macs and other *nix like operating systems when you type a command in the command line, what is actually happening is the shell is trying to find the executable file in a predefined area, called the PATH variable. If you are interested check out this question, https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them.

You are able to see what yours is set to if you do this in your command line

echo $PATH

this will give you some file paths separated by colons, for example when I type the command above I get this:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Applications/Android Dev Tool/sdk/tools

which means that my shell will check for a executable in each of these files, if it finds it, it will run otherwise it will tell you the program can't be found. As a side note this is the reason why when you run an executable not in one of these PATH files you must do,

./program

this is specifying a relative path to the executable file, the current directory that you are in.

So for you, you installed pip to this directory:

/Library/Python/2.7/site-packages

chances are the above echo statement did not include this file, if it did then you have another problem. What you need to do is to update your PATH variable to include this directory as well. To do this you add an export statement to your .bash_profile (or .bashrc on Linux) in your home directory (this is a hidden file) that includes your current path variables (so you will still be able to run everything installed in the proper place) and this new directory that you installed pip to. To do this add this line to the end of your .bash_profile

export PATH=${PATH}:/Library/Python/2.7/site-packages

and you should be good to go. However before it will take effect you need to close and open your terminal window again or run source .bash_profile. You can verify this worked by running the echo command above, it should return the same thing but this time with /Library/Python/2.7/site-packages appended to the end.

Note: By the way the which command that you were told to run in the comments locates a program within the users path, which is why it did not return anything to you. Also since you will probably run into this soon enough there is also a variable called PYTHONPATH (look here) which tells python where to look to import modules. You should set this to whatever directory you have pip installing modules to if it is not already set.

Upvotes: 2

Related Questions