Imagine Python as a workshop. It already comes with a toolbox full of built-in tools — math, random, datetime, etc. But what if you need something more — like connecting to the internet, analyzing data, or building a web app?

You could write everything from scratch… Or simply install ready-made tools built by other developers around the world.

Those ready-made tools are called third-party packages. And the tool used to install and manage them is pip, which stands for “Pip Installs Packages.”


⚙️ What is pip?

pip is Python’s package manager — a command-line tool that lets you:

  • Install third-party libraries from the Python Package Index (PyPI).
  • Upgrade or uninstall packages.
  • List installed packages.
  • Share project dependencies with others.

It’s like the App Store for Python, but for programmers. When you install Python, pip usually comes preinstalled.


🧩 Checking if pip is Installed

Before installing packages, check whether pip is available on your system.

Open your terminal or command prompt and type:

pip --version

Example output:

pip 24.0 from C:\Python312\Lib\site-packages\pip (python 3.12)

✅ If you see a version number, pip is installed. ❌ If not, you can install it by running:

python -m ensurepip --upgrade

📦 Installing a Package

To install a third-party package, use the command:

pip install package_name

Example:

pip install requests

This command connects to the Python Package Index (PyPI) — the official online repository at https://pypi.org — downloads the package, and installs it into your system.

Output might look like:

Collecting requests
Downloading requests-2.31.0-py3-none-any.whl (63 kB)
Installing collected packages: requests
Successfully installed requests-2.31.0

🎉 You’ve just expanded Python’s powers!

Now you can use it in your code:

import requests
response = requests.get("https://www.python.org")
print(response.status_code)

🧠 How Packages Are Organized

When installed, each package lives inside your Python’s site-packages folder. You can find this directory using:

import site
print(site.getsitepackages())

This helps Python locate modules when you write import package_name.


🔁 Upgrading a Package

Sometimes you need a newer version of a package to get the latest features or bug fixes.

Use:

pip install --upgrade package_name

Example:

pip install --upgrade requests

pip will check PyPI for a newer version and replace the old one.


❌ Uninstalling a Package

To remove an unwanted or outdated package, type:

pip uninstall package_name

Example:

pip uninstall requests

You’ll be prompted to confirm before deletion.


📋 Listing Installed Packages

To see all packages installed on your system:

pip list

Output Example:

Package      Version
------------ -------
pip          24.0
requests     2.31.0
numpy        1.26.3

📄 Saving and Sharing Dependencies

When working on projects, it’s good practice to record which packages you installed so that others can reproduce your environment.

You can generate a list using:

pip freeze > requirements.txt

This creates a requirements file, e.g.:

requests==2.31.0
numpy==1.26.3
pandas==2.2.2

To install all the packages from another developer’s requirements.txt, use:

pip install -r requirements.txt

This ensures every teammate or student uses the same versions — crucial for teamwork, reproducibility, and deployment.


🧰 Installing Specific Versions

You can install a particular version of a package like this:

pip install package_name==version_number

Example:

pip install numpy==1.24.2

This is useful when newer versions break compatibility with your code.


🧩 Installing from URLs or Local Files

  • From a GitHub repository:

    pip install git+https://github.com/user/repo.git
    
  • From a local .whl or .tar.gz file:

    pip install mypackage-1.0.0-py3-none-any.whl
    

This flexibility makes pip ideal for both development and production use.


🧱 Virtual Environments (Best Practice)

As your learners grow, they’ll discover virtual environments — isolated workspaces that let you install packages for one project without affecting others.

To create one:

python -m venv myenv

Activate it:

  • Windows:

    myenv\Scripts\activate
    
  • macOS/Linux:

    source myenv/bin/activate
    

Now any package you install with pip install stays within that environment only — safe and clean.

Deactivate when done:

deactivate

🧮 Troubleshooting Common pip Issues

Problem Possible Solution
“pip not recognized” Add Python’s Scripts folder to PATH or reinstall Python with “Add to PATH” checked
Permission denied Run with --user or use admin privileges
Outdated pip Upgrade using python -m pip install --upgrade pip
Installation failed Check internet connection or install correct version for your Python release

🧭 Summary

Command Purpose
pip install package Install a package
pip uninstall package Remove a package
pip list List installed packages
pip show package Display info about a package
pip freeze > requirements.txt Save current dependencies
pip install -r requirements.txt Install packages from a file
pip install --upgrade package Upgrade a package
python -m pip install --upgrade pip Upgrade pip itself

Review Fill-in-the-Gap Questions

  1. The tool used to install third-party Python packages is called __.
  2. The term pip stands for “__ Installs Packages.”
  3. The official repository for Python packages is called __.
  4. To check if pip is installed, type the command __ in the terminal.
  5. The command to install a package named numpy is __.
  6. To upgrade a package to its latest version, we use pip install ______ package_name.
  7. To remove a package completely, we use the command pip ______ package_name.
  8. The command pip freeze > requirements.txt is used to create a list of __.
  9. Installing packages inside a project-specific environment can be done with a tool called __.
  10. The file that lists all required packages for a project is usually named __.

<
Previous Post
Drawing A Square Using Canvas: HTML, CSS and JavaScript
>
Blog Archive
Archive of all previous blog posts