How to Install a Package in Python using PIP

In this short guide, you’ll see how to install a package in Python using PIP. You’ll also learn how to uninstall a package that is no longer needed.

If you’re using Windows, you’ll be able to install a Python package by opening the Windows Command Prompt, and then typing this command:

pip install package_name

Note: the above method would only work if you already added Python to Windows path. Don’t worry if you don’t know what it means, as you’ll see the full steps to install a package in Python using PIP.

Here are the topics to be reviewed:

    • Simple example with the steps to install the pandas package
    • Uninstall a Python package

Steps to Install a Package in Python using PIP

(1) First, type Command Prompt in the Windows search box

(2) Next, open the Command Prompt, and you’ll see the following screen with your user name (to avoid any permission issues, you may consider to run the Command Prompt as an administrator):

C:\Users\Ron>

(3) In the Command Prompt, type “cd\” as this command will ensure that your starting point has only the drive name:

C:\Users\Ron>cd\

(4) Press Enter. Now you’ll see the drive name of C:\>

C:\>

(5) Locate your Python Scripts path. The Scripts folder can be found within the Python application folder, where you originally installed Python.

Here is an example of a Python Scripts path:

C:\Users\Ron\AppData\Local\Programs\Python\Python39\Scripts

(6) In the Command Prompt, type cd followed by your Python Scripts path:

C:\>cd C:\Users\Ron\AppData\Local\Programs\Python\Python39\Scripts

(7) Press Enter, and you’ll see something similar to the following:

C:\Users\Ron\AppData\Local\Programs\Python\Python39\Scripts>

(8) Now, type the pip install command to install your Python package. The pip install command has the following structure:

pip install package_name

Since in our case, we would like to install the pandas package, then type the following command in the Command Prompt:

pip install pandas 

C:\Users\Ron\AppData\Local\Programs\Python\Python39\Scripts>pip install pandas

(9) Finally, press Enter, and you’ll notice that the package (here it’s pandas) will be installed:

Successfully installed pandas-1.2.4

You can quickly check if the package was successfully installed in Python, by opening the Python IDLE and then running the command “import pandas”

If no errors appear, then the package was successfully installed.

If you’re dealing with Anaconda, you may also want to check how to install a package using Anaconda.

Uninstall a Package using PIP

To uninstall a package using PIP, simply type the following command in the Command Prompt (do not forget to set the Python Scripts path before you type this command):

pip uninstall package_name