Python comes with a rich standard library — a built-in collection of modules that handle common tasks like mathematics, random number generation, working with dates and times, and basic file operations. For many programs, these built-in tools are enough. But modern software often requires capabilities beyond the standard library, such as making web requests, processing large datasets, building APIs, or performing machine learning.

Instead of writing all of that functionality from scratch, Python allows developers to install third-party packages — reusable libraries created and maintained by developers worldwide. These packages are distributed through an online repository, and the primary tool used to install and manage them is called pip.

The name pip stands for “Pip Installs Packages.” It is Python’s package manager, meaning it handles downloading, installing, upgrading, and removing external libraries. In most modern Python installations, pip is included automatically.

Before installing packages, it is useful to confirm that pip is available on your system. This is done through the command line:

pip --version

If pip is installed, the command will display its version along with the Python version it is linked to. If it is not installed, Python provides a built-in way to install it:

python -m ensurepip --upgrade

Once pip is ready, installing packages is straightforward. The general pattern is:

pip install package_name

For example, installing the popular HTTP library requests looks like this:

pip install requests

When you run this command, pip connects to the Python Package Index, downloads the package files, and installs them into your Python environment. After installation, the package becomes available for import in your programs.

import requests

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

Behind the scenes, installed packages are placed inside a directory called site-packages, which is where Python searches for external modules. You can inspect these locations using:

import site
print(site.getsitepackages())

Software evolves, and packages are updated regularly to fix bugs or add features. To upgrade an installed package, you can run:

pip install --upgrade package_name

For example:

pip install --upgrade requests

If you no longer need a package, you can remove it completely:

pip uninstall package_name

This will usually ask for confirmation before deleting the package files.

To see all packages currently installed in your environment, you can use:

pip list

This displays package names alongside their installed versions.

In real-world development, especially when working in teams or deploying applications, it is important to track dependencies. Python developers commonly use a file called requirements.txt to store package versions.

You can generate this file using:

pip freeze > requirements.txt

The file will contain entries like:

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

Another developer can recreate the same environment by running:

pip install -r requirements.txt

This ensures consistency across different machines and deployment environments.

Sometimes projects depend on specific package versions. You can install a precise version using:

pip install package_name==version_number

For example:

pip install numpy==1.24.2

This is especially useful when newer versions introduce breaking changes.

pip is also flexible enough to install packages from alternative sources. For example, you can install directly from a Git repository:

pip install git+https://github.com/user/repo.git

Or from a locally downloaded package file:

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

As projects grow, developers typically move to using virtual environments. A virtual environment is an isolated Python workspace that keeps project dependencies separate from system-wide packages. This prevents version conflicts between projects.

You can create a virtual environment using:

python -m venv myenv

To activate it:

On Windows:

myenv\Scripts\activate

On macOS or Linux:

source myenv/bin/activate

While active, any packages you install using pip will be installed only inside that environment. When you are done working, you can exit the environment using:

deactivate

Like any tool, pip sometimes encounters issues. Common problems include missing PATH configuration, permission restrictions, or outdated versions of pip. For example, upgrading pip itself is done using:

python -m pip install --upgrade pip

Overall, pip is central to modern Python development. It allows developers to leverage the work of the global Python community, speeds up development time, and makes it easy to share and reproduce working software environments. By mastering pip and dependency management early, developers set a strong foundation for building reliable, maintainable Python applications.


<
Previous Post
Drawing A Square Using Canvas: HTML, CSS and JavaScript
>
Next Post
Python List Comprehensions: A faster, Cleaner, And Smarter Way To Create Lists In Python