📒 

PIP (Python Package Installer) is the primary tool used for installing and managing packages in Python. Whether you’re a beginner exploring Python development or a seasoned developer working on complex projects, PIP is essential for downloading and managing external libraries and dependencies. In this guide, we’ll walk through the process of installing PIP on Windows, ensuring that you’re fully set up to manage Python packages on your system.

Why Do You Need PIP?

PIP allows you to easily install, upgrade, and uninstall Python packages from the Python Package Index (PyPI) and other package repositories. Some of the benefits of using PIP include:

  • Convenience: Install any Python library or module with a single command.
  • Dependency Management: Automatically resolves and installs any dependencies required by a package.
  • Package Updates: Allows you to easily upgrade to the latest versions of libraries.
  • Ease of Use: Simple syntax for installing, uninstalling, and listing packages.

Prerequisites

Before we start with the installation of PIP, here are a few things you’ll need to have:

  • Python Installed: PIP comes bundled with most Python installations. Ensure you have Python installed on your Windows machine.
  • Administrator Access: You’ll need admin privileges to install software.

Step 1: Verify Python Installation

First, let’s make sure Python is installed on your system. If Python isn’t installed yet, you can download it from the official Python website.

  1. Open Command Prompt. You can do this by searching for “cmd” in the Start menu.
  2. In the Command Prompt, type the following command:
    python --version

    This will display the current version of Python installed on your machine. If Python is not installed, you’ll need to install it before proceeding.

  3. You can also check if Python is installed correctly by typing:
    python

    This command will launch the Python interpreter if Python is properly installed.


Step 2: Check if PIP is Already Installed

In many cases, PIP is installed automatically when you install Python. To check if PIP is installed, follow these steps:

  1. Open Command Prompt.
  2. Type the following command and press Enter:
    pip --version

    If PIP is installed, you’ll see the version number, like this:

    pip 21.1.1 from C:\Python39\lib\site-packages\pip (python 3.9)

    If PIP is not installed or you receive an error message, proceed to the next step to install PIP manually.


Step 3: Download and Install PIP Manually

If you don’t have PIP installed, you’ll need to install it manually by downloading a script called get-pip.py.

  1. Open your browser and download the get-pip.py script from the official PIP website. You can do so by visiting:

    get-pip.py

  2. Save the file to an easily accessible location, such as your Desktop or Downloads folder.
  3. Open Command Prompt and navigate to the directory where you saved the get-pip.py file. Use the cd command to change directories. For example:
    cd Desktop
  4. Once you’re in the correct directory, run the following command to execute the get-pip.py script:
    python get-pip.py

    This will download and install PIP on your system.

  5. After the installation completes, verify that PIP is successfully installed by running:
    pip --version

    You should now see the version of PIP displayed in the command line.


Step 4: Add PIP to the Windows PATH

If you encounter the error 'pip' is not recognized as an internal or external command, it means that PIP is not added to your system’s PATH environment variable. To fix this, follow these steps:

  1. Locate the PIP Installation Directory:
    • In Command Prompt, type:
      where python

      This command will show the directory where Python is installed. Typically, this will be something like C:\Python39\Scripts\ or C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python39\Scripts\.

  2. Add the Directory to PATH:
    • Right-click the Start menu and select System.
    • Click on Advanced system settings on the right.
    • In the System Properties window, click Environment Variables.
    • In the Environment Variables window, find the Path variable under System variables and click Edit.
    • In the Edit Environment Variable window, click New and paste the path to the PIP installation directory (e.g., C:\Python39\Scripts\).
    • Click OK to save the changes.
  3. Verify the PATH Update:
    • Close and reopen Command Prompt, then type:
      pip --version
    • You should now be able to run PIP commands without any issues.

Step 5: Upgrading PIP (Optional)

PIP is continuously updated, and it’s important to keep it up to date to ensure compatibility with the latest packages. You can easily upgrade PIP by running the following command:

python -m pip install --upgrade pip

This command will download and install the latest version of PIP.


Step 6: Testing PIP by Installing a Package

To ensure that PIP is working correctly, let’s install a simple Python package. For this example, we’ll install the requests library, which is a popular library for making HTTP requests in Python.

  1. Open Command Prompt.
  2. Type the following command:
    pip install requests
  3. Once installed, you can test it by opening the Python interpreter and importing the requests module:
    python

    Inside the Python interpreter, type:

    import requests
    print(requests.__version__)

    This should print the installed version of the requests library, indicating that PIP is working correctly.


Step 7: Uninstalling Packages with PIP (Optional)

If you ever need to remove a package installed by PIP, you can easily do so by running the following command:

pip uninstall <package_name>

For example, to uninstall the requests library:

pip uninstall requests

PIP will prompt you to confirm the uninstallation, and the package will be removed from your system.


Conclusion

Installing PIP on Windows is a straightforward process that opens the door to thousands of Python libraries available through the Python Package Index (PyPI). Whether you’re a beginner learning Python or a developer working on complex projects, PIP makes it easy to manage external libraries and keep your development environment up to date.

With PIP installed, you can now begin installing, managing, and upgrading Python packages on your Windows system. Happy coding!