Installation & uninstallation of packages in Python

Key takeaways:

  • pip makes it easy to install, uninstall, and upgrade Python packages, streamlining dependency management for developers.

  • It connects to the Python Package Index (PyPI), allowing you to access thousands of third-party libraries and tools for various tasks.

  • With version control and automatic dependency handling, pip helps maintain a clean and functional development environment.

In Python, you can install and uninstall packages using the pip tool, which is the standard package manager for Python. pip (short for “Pip Installs Packages”) is an essential tool that helps you manage third-party libraries and dependencies in your Python environment. It is included by default in Python installations from version 3.4 onwards, making it readily available for most Python users.

pip interacts with the Python Package Index (PyPI), a large repository that hosts thousands of Python libraries and packages, allowing developers to easily share and distribute their work. By using pip, developers can quickly install packages for a wide variety of purposes, such as data manipulation (pandas, numpy), web development (Flask, Django), machine learning (scikit-learn, tensorflow), and more.

Package

All the files needed for a module are contained in a package.

  • Packages are installed based on the project requirement.
  • Before you install packages, check if pip is installed—if it’s not installed, download PIP. pip is a package manager for Python packages or modules.

Note: If you have Python version 3.4 or later, PIP is included by default.

How to check the pip version

Go to command prompt and navigate to the Python directory as shown:

C:\Users\Your Name\AppData\Local\Programs\Python\Python36\Scripts>pip --version

Note: This is C:\Users\Your Name\AppData\Local\Programs\Python\Python36\Scripts Python directory in our case.

svg viewer

How to install a package

  1. Go to the command prompt.
  2. Navigate to the Python Scripts directory (as shown above).
  3. Now type:
pip install package-name

Example

C:\Users\Your Name\AppData\Local\Programs\Python\Python36\Scripts>pip install matplotlib

How to uninstall a package

  • Use uninstall to remove the package.

Example

C:\Users\Your Name\AppData\Local\Programs\Python\Python36\Scripts>pip uninstall matplotlib
  • It will ask whether to remove the package or not (y/n?) for confirmation.
  • y is for removing.
  • n is for not removing.

Packages list

To check all the packages in Python, use the pip list command.

Example

C:\Users\Your Name\AppData\Local\Programs\Python\Python36\Scripts>pip list
  • A list of installed packages will be displayed.

The same process is repeated for all the packages.

Try it yourself

Now, let’s try some of the previously mentioned commands in the widget below:

  1. Press the “Run” button.
  2. The console will appear in the current Python directory.
  3. Try running commands:
  • pip --version
  • pip install package_name
  • pip uninstall package-name
  • pip list

Start coding with confidence! “Learn Python 3 from Scratch” takes you through Python fundamentals and program structures, culminating in a practical project to solidify your skills.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


How do I uninstall and install Python?

  • Uninstall:

    • Windows: Use the Control Panel or the installer.
    • macOS: Delete from the Applications folder.
    • Linux: Use your package manager (e.g., sudo apt remove python3).
  • Install:

    • Download from python.org.
    • Install using the installer (Windows/macOS) or package manager (Linux).
    • For Windows, check “Add Python to PATH.

What are the four types of installation?

This refers to the system conversion process when transitioning from an old system to a new one. The four approaches are:

  • Direct installation: The old system is immediately replaced by the new one.
  • Parallel installation: Both systems run simultaneously for a period.
  • Single-location installation: The new system is implemented in one location first before rolling out to others.
  • Phased installation: The new system is implemented gradually in stages.

What is the difference between installing and uninstalling a program?

Installing a program adds it to a system and sets it up for use, while uninstalling removes it completely, including associated files and configurations.


Free Resources