How to run Pip commands from CMD
Solution 1
Little side note for anyone new to Python who didn't figure it out by theirself: this should be automatic when installing Python, but just in case, note that to run Python using the python
command in Windows' CMD you must first add it to the PATH
environment variable, as explained here.
To execute Pip, first of all make sure you have it installed, so type in your CMD:
> python
>>> import pip
>>>
And it should proceed with no error. Otherwise, if this fails, you can look here to see how to install it. Now that you are sure you've got Pip, you can run it from CMD with Python using the -m
(module) parameter, like this:
> python -m pip <command> <args>
Where <command>
is any Pip command you want to run, and <args>
are its relative arguments, separated by spaces.
For example, to install a package:
> python -m pip install <package-name>
Solution 2
Newer versions of Python come with py
, the Python Launcher, which is always in the PATH
.
Here is how to invoke pip
via py
:
py -m pip install <packagename>
py
allows having several versions of Python on the same machine.
As an example, here is how to invoke the pip
from Python 2.7:
py -2.7 -m pip install <packagename>
Solution 3
Make sure to also add "C:\Python27\Scripts" to your path. pip.exe should be in that folder. Then you can just run:
C:\> pip install modulename
Solution 4
Go to the folder where Python is installed .. and go to Scripts folder .
Do all this in CMD and then type :
pip
to check whether its there or not .
As soon as it shows some list it means that it is there .
Then type
pip install <package name you want to install>
Solution 5
Simple solution that worked for me is, set the path of python in environment variables,it is done as follows
- Go to My Computer
- Open properties
- Open Advanced Settings
- Open Environment Variables
- Select path
- Edit it
In the edit option click add and add following two paths to it one by one:
C:\Python27
C:\Python27\Scripts
and now close cmd and run it as administrator, by that pip will start working.
algorhythm
I am a software support engineer for a company that develops and maintains traffic management software.
Updated on October 06, 2021Comments
-
algorhythm over 2 years
As I understand, Python 2.7.9 comes with Pip installed, however when I try to execute a Pip command from CMD (Windows) I get the following error:
'pip' is not recognized as an internal or external command, operable program or batch file.
When I type
python
I do get the following, which suggests it has been installed correctly:Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
I did however need to add some environmental variables to get the python part working on CMD:
Add to the environment variable
PATH
:"C:\Python27\"
Define the system variable
PYTHONPATH
:"C:\Python27\"
I cannot find a Pip folder within the Python directory, however there is a folder called "ensurepip" in
C:\Python27\Lib\
.Does anybody know how can I get Pip commands to start working in CMD?
-
Bill Kidd almost 8 yearsIf you work behind a firewall you may need to include your proxy server as an argument to your pip command. pip --proxy YourProxyUrl:81 install pythonnet
-
Anton Balashov over 7 yearspython -m pip install /usr/bin/python: pip is a package and cannot be directly executed
-
MadmanLee over 5 yearsWhat is the "-m"
-
Marco Bonelli over 5 years@MadmanLee "m" stands for module, it launches a module executing it as a script rather than importing it.
-
Akin Hwan over 5 yearsis there a way to just call "pip" instead of preceding with "py -m" ? do i need to update PATH or something? or just create an alias?
-
Benoit Blanchon over 5 years@AkinHwan, you would have to add it to the
PATH
, because only thepy
command is exposed by default. It makes sense since you could have several versions of Python on your computer,py
allows you to select the one you want.