How to Install the Python Package Manager pip on Windows

Beatme CodeBY-NC-ND
9:49 read·1277 words· modified

Determine If pip is Installed on Windows

For Windows, if you download and install the latest installer of Python from the official Python website, pip will be installed by default, unless the pip component is not selected during a custom installation, or if you use an embeddable package, NuGet, or some other installation method.

If you are unsure if Windows has pip installed or if pip is available, you can enter the command python -m pip --version at Command Prompt. When pip is available, its version and the directory where it is located will be displayed, otherwise you may get the message No module named pip.

python -m pip --version
pip 23.2.1 from \Lib\site-packages\pip (python 3.11)

Run the pip executable file to determine if pip is installed on Windows

In addition to the above command python -m pip --version, which causes Python to try to run the module pip (you can simply understand installing pip as installing the pip module), running the pip executable file directly is also a way of determining whether or not Windows has pip installed, by simply typing pip --version at the command line (which displays the version and directory of pip, or something like “Command does not exist”). In fact, the pip executable file itself still runs the Python module pip, which is the same as running the module pip directly, but with a much easier command writing.

Of course, in some installations, the pip executable file is not required, so the command line may also prompt a message like “Command does not exist” if you did not choose to install the pip executable file when installing pip.

pip --version
pip 23.2.1 from \Lib\site-packages\pip (python 3.11)

After installing pip on Windows, running pip still prompts No module named pip

If you do have pip installed on Windows, and you run python -m pip --version but still get the message No module named pip, then the problem may be that Python’s Module Search Path does not include the directory where the module pip is located. You can check the Python Module Search Path to see if you need to change it.

Install pip on Windows with the Python ensurepip Package

You can simply install pip manually using the package ensurepip, but you need to make sure that it exists, because not all installations contain ensurepip, such as embedded installers that contain minimal components. In addition, the package ensurepip should be found by Python, and if you get a message like No module named ensurepip, check that the Module Search Path contains the directory where ensurepip is located.

By default, if Python can find any available pip in Windows, the ensurepip package will not proceed with the installation (even if a different install location is specified) unless the --upgrade option is used to attempt an update.

python -m ensurepip <options>
--default-pip, --altinstall options

The --default-pip option means that pip.exe, pip<X>.exe, and pip<X>.<Y>.exe will be installed to the Scripts folder, and if the --altinstall option is used, only pip<X>.<Y>.exe will be installed, where X is the major version number and Y is the minor version number. When neither of these options is used, pip<X>.exe and pip<X>.<Y>.exe will be installed.

--upgrade option

Using the option --upgrade allows ensurepip to attempt to update the currently installed pip to the latest version provided by the ensurepip package (which may not be the same as the latest version of pip on PyPI).

--root argument,--user option

The --root argument and the --user option are used to change the installation location of pip, where the --root argument specifies a directory where pip will be installed and its directory structure will be consistent with the installation directory structure of Python itself, and the --user option (which is unavailable in virtual environments) indicates that pip will be installed in the Windows user app data folder.

The pip installed by the Python ensurepip package is provided by the ensurepip package itself

You can still install pip on Windows via Python’s ensurepip package even if you don’t have a network, because pip is already included in the package ensurepip, which means that pip installed via ensurepip may not be the latest version.

Add the Scripts directory to the Windows PATH environment variable

If the path to the Scripts folder generated by the installation is not included in the Windows environment variable PATH, then it may not be possible to use the pip executable files because the command line can’t locate them, and it will be necessary to manually add the Scripts directory to the Windows environment variable PATH.

Install pip on Windows Using the Python Script File get-pip.py

If the Python package ensurepip is missing, you can also install pip in Windows by downloading and executing the get-pip.py file. All you need to do is choose a directory to download and save get-pip.py, then launch Windows’ Command Prompt and go to that directory, and finally execute get-pip.py using Python.

The installation of get-pip.py is essentially similar to using the package ensurepip, with pip.exe, pip<X>.exe, and pip<X>.<Y>.exe being installed into the Scripts folder. But in addition, get-pip.py installs wheel and setuptools, with wheel.exe located in Scripts and setuptools only in Lib\site-packages.

bootstrap.pypa.io/get-pip.py

python get-pip.py
--no-setuptools option

The --no-setuptools option means that no attempt will be made to install setuptools along with pip.

--no-wheel option

The --no-wheel option means that no attempt will be made to install wheel along with pip.

How can I install specific versions of pip, wheel and setuptools on Windows using the Python script file get-pip.py?

When running the get-pip.py file via Python, you can select the version of pip, wheel and setuptools by entering a version condition, e.g., "pip==21.0" means that version 21.0 of pip will be installed, "pip<24" means that the latest version of pip with a version less than 24 will be installed, "pip>= 19.1" means that the latest version of pip with a version greater than or equal to 19.1 will be installed.

python get-pip.py <packages>
packages value

packages contains version information for the pip, wheel, and setuptools packages, each of which can be enclosed in " and separated by spaces, or the latest version if no version is specified, e.g., python get-pip.py "pip>=23" "wheel" will install the latest version of wheel (since setuptools is not given, setuptools is only installed if it doesn't exist, but interestingly, pip will be installed whether or not pip is given). It should be noted that get-pip.py does not determine whether the version to be installed is newer than the one already installed, and the original version will be uninstalled, even if the version being installed is older.

Install additional Python packages on Windows using the script file get-pip.py

Yes, you can install any other Python package using the script file get-pip.py, e.g., python get-pip.py "numpy" will install the packages pip and numpy at the same time, which may seem strange, but it works.

Run Python Script Files, Modules, Packages

To learn more about executing Python scripts from the command line, you can check out the section How to Run Python Scripts Files, Modules, Packages from the Command Line.

The Installation Location of pip on Windows

By default, pip will be installed into the directory where Python resides, with its executable files and source code located in the Scripts and Lib\site-packages folders, respectively.

The location of pip on Windows depends on which Python is running at the time of installation

When the Windows environment variable PATH contains multiple paths to Python, check the location of the Python that is executed on the command line, as pip may be installed there when installed manually using ensurepip or get-pip.py. This is very important, especially if you have multiple versions of Python.