Search code examples
pythonpython-2.7pip

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


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?


Solution

  • 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.