Download How to Install Pip on Windows - Python
Categories:Viewed: 65 - Published at: 7 months ago

Introduction

Package managers are tools commonly created for programming languages that make the setup and management of third-party packages easier. Pip is the preferred package manager in Python for both the native Pip modules and the ones installed inside the virtual environments. When Pip is invoked, it automatically crawls against the repository of public Python packages (the Python Package Index, also known as PyPI), downloads the package(s), and installs the setup files. In this article, we will be learning to install Pip in Windows-based Operating systems.

Pip Installation on Windows

Python Installation

Let's check if Python and Pip are already installed on our Windows-based OS. Let's fire up our Windows Terminal from the start menu - we'll be using PowerShell through it. You can also use the PowerShell Terminal, but Windows Terminal gives you a better developer experience, and gives you easy access to other powerful Linux or macOS shells. Once the window opens, key in the following command to check if Python is installed:

PS C:\> python --version
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

If you are looking at a message like that of the above, Python is not installed on your machine. You may download the latest version of Python from the official download page. Choose the version that you would like to download (If your RAM size is greater than 4GB, your machine should be of a 64Bit architecture, so make sure you get an AMD64 version of the executable). Upon download, locate your Downloads directory and double-click on the downloaded executable. Follow along the steps provided in the window and install your version of Python, as shown below:

Python Installation Steps

Now that Python has been downloaded and installed, let's open the terminal again and provide the following command:

PS C:\> python --version
Python 3.9.5

Pip Installation

Modern versions of Python, i.e. version 3.4 and higher, come with Pip pre-installed along with the version of Python. This can be checked by keying in the following command:

PS C:\> pip --version
pip 21.1.1 from c:\users\stackabuse\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)

If you see something different from the message above, it means that Pip is either not installed or corrupted on your machine:

PS C:\> pip --version
pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ pip --version
+ ~~~
    + CategoryInfo          : ObjectNotFound: (pip:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The message above shows that Pip is not installed on your machine. In this case, you need the source code to set up Pip your machine. This can be downloaded from bootstrap.pypa.io using wget on your machine. This downloads the source code to a local file get-pip.py:

PS C:\> wget https://bootstrap.pypa.io/get-pip.py -OutFile get-pip.py

The mentioned file contains the source code to install the latest version of Pip. Since it's a Python file itself, it can be invoked in the same way all Python scripts are executed:

PS C:\> python get-pip.py
Collecting pip
  Downloading pip-21.1.1-py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 384 kB/s
Collecting wheel
  Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, pip
Successfully installed pip-21.1.1 wheel-0.36.2

The message shows that the latest version of Pip has been installed on your machine. As a confirmation, you can also check if you had installed the recent version of the Pip by invoking the following command:

PS C:\> pip --version
pip 21.1.1 from c:\users\stackabuse\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)

Uninstalling Pip

There could be times when your existing version of Pip might get corrupted after an update, or perhaps wanted to do a fresh installation. The following command can be used to uninstall Pip entirely:

PS C:\> pip uninstall pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
  Would remove:
    c:\users\sathy\appdata\local\programs\python\python39\lib\site-packages\pip-21.1.1.dist-info\*
    c:\users\sathy\appdata\local\programs\python\python39\lib\site-packages\pip\*
    c:\users\sathy\appdata\local\programs\python\python39\scripts\pip.exe
    c:\users\sathy\appdata\local\programs\python\python39\scripts\pip3.9.exe
    c:\users\sathy\appdata\local\programs\python\python39\scripts\pip3.exe
Proceed (y/n)? y
  Successfully uninstalled pip-21.1.1

Conclusion

Pip is one of the most popular package managers used by Python developers. For the most recent versions of Python, it is already installed on Windows. However, we can easily manage our Pip installation in case of errors by using a safe, Python script to install the latest version, and by using Pip itself to remove it from our system.

Reference: stackabuse.com

TAGS :