Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "-m" needed for "python -m pip install ..."?

Tags:

pip

python-2.7

I recently used pip to install the requests package in python 2.7, however in order to do so I had to use:

python -m pip install requests 

instead of just:

python pip install requests

which gave me an error:

can't open file 'pip: [Errno 2] No such file or directory

Why did I need to add the -m?

like image 807
Mwspencer Avatar asked Nov 03 '16 01:11

Mwspencer


1 Answers

python -m pip tells python to run with the pip module as the main module.

python pip isn't understood, because pip isn't a command line argument that python understands (i.e., pip is a module).

If the python scripts directory (c:\python27\scripts for python 2.7 on windows) is on your path, then you can just run pip (without python before it) and pass the same options you would pass to python -m pip.

So: you need to add -m pip so python knows what module to use as the main module. pip is a standalone program installed in your python scripts directory, not an argument to python.

like image 195
cco Avatar answered Oct 17 '22 20:10

cco