How to Install a Package in Python using PIP

In this short guide, I’ll show you how to install a package in Python using PIP. I’ll also demonstrate 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 in the next section, I’ll cover 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
  • Tool that will allow you to easily install/uninstall Python packages

Steps to Install a Package in Python using PIP

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

 

command prompt

 

(2) Right click on the Windows Command Prompt. Then, select Run as administrator (by running the Command Prompt as an administrator, you’ll avoid any permission issues):

 

Command Prompt

 

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

 

Admin command prompt

 

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

 

Administrator command prompt

 

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

In my case, the Python Scripts path is:

C:\Users\Ron\AppData\Local\Programs\Python\Python37-32\Scripts

 

Python Scripts Path

 

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

 

Python Scripts

 

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

 

How to Install a Package in Python using PIP

 

(7) 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 

 

How to Install a Package in Python using PIP

 

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

 

pip install - Python

 

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 (after you press F5 to run the import command), then the package was successfully installed.

Mission Accomplished!

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

 

In our case, type: pip uninstall pandas and then press Enter:

 

How to Uninstall a Package in Python using PIP

 

Finally, type y and then press Enter in order to proceed with the removal of the package:

 

Uninstall a Package using PIP

Tool to install/uninstall a Python Package

Now I’ll share with you the code to install/uninstall Python packages using a simple tool I created.

Note that you’ll need to add Python to Windows path before you can start using the tool.

Here is the full Python code:

 

import os
import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 300, height = 350, bg = 'gray90', relief = 'raised')
canvas1.pack()

label1 = tk.Label(root, text='Type Package:', bg = 'gray90')
label1.config(font=('helvetica', 14))
canvas1.create_window(150, 80, window=label1)


entry1 = tk.Entry (root, width=27)
canvas1.create_window(150, 120, window=entry1)


def installPackage ():
    global installPythonPackage
    installPythonPackage = 'pip install ' + entry1.get()
    
    os.system('start cmd /k ' + installPythonPackage)


def uninstallPackage ():
    global uninstallPythonPackage
    uninstallPythonPackage = 'pip uninstall ' + entry1.get()
    
    os.system('start cmd /k ' + uninstallPythonPackage)

    
button1 = tk.Button(text='      Install Package    ', command=installPackage, bg='green', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 180, window=button1)


button2 = tk.Button(text='   Uninstall Package  ', command=uninstallPackage, bg='coral3', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 230, window=button2)

root.mainloop()

 

Simply run the code in Python and you would see the following screen:

 

How to Install a Package in Python using PIP

 

Type the package name that you’d like to install or uninstall. For example, type the package name pandas, and then click on the green button to install the package:

 

Install a Package in Python using PIP

 

That’s it! You should be able to enjoy the pandas package!