Python development relies heavily on external libraries to handle complex tasks like data analysis or web scraping. You might encounter a scenario where you try to run a script only to receive an “ImportError,” or you may need to deploy a web application that requires a specific version of a framework. Without the pip command, manually downloading and managing these dependencies across your Linux file system would be nearly impossible.
Pip is the standard package manager for Python, allowing you to install, update, and remove software from the Python Package Index (PyPI) instantly. Whether you are working on a local Ubuntu machine or a remote Red Hat server, mastering pip ensures your development environment stays organized and functional. This guide explains how to use the most common pip commands to manage your Python projects efficiently. Before you begin, it is a good idea to check your Python version to ensure compatibility with your environment.
Table of Contents
Key Takeaways: Mastering Python Packages
- PyPI → The central repository where thousands of open-source Python libraries are hosted.
- pip install → The primary command used to fetch and set up new libraries on your system.
- Requirements File → A text file (usually
requirements.txt) that lists every dependency needed to replicate an environment. - Virtual Environments → Best practice for isolating projects to prevent library version conflicts.
- Upgrade Flag → Used to ensure you are running the latest security patches for your installed tools.
Method 1: Installing New Packages
The most common use for pip is installing a library from the web. By default, pip connects to PyPI to find the latest version of the requested software.
Command: pip install requests
Expected Output:
Collecting requests
Downloading requests-2.31.0-py3-none-any.whl (62 kB)
Installing collected packages: requests
Successfully installed requests-2.31.0
Note: Depending on your system configuration, you may need to use the sudo command if you are installing packages globally.
Method 2: Listing and Auditing Installed Packages
To maintain system health, you should regularly audit which libraries are currently taking up space on your storage. This is similar to how you would check file size in Linux to monitor disk consumption.
Command: pip list
Expected Output:
Package Version
------------------ ---------
pip 24.0
requests 2.31.0
setuptools 68.0.0
This reveals every package installed in your current environment along with its specific version number.
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
Method 3: Uninstalling and Cleaning Up
If a library is no longer needed or if you are troubleshooting a slow environment, you can remove it to free up resources.
Command: pip uninstall requests
You will be asked to confirm the deletion. Type y and press Enter to finalize the removal. For a more thorough cleanup of your Linux machine, you can also use terminal commands to clean your system.
Step-by-Step Process: Replicating a Project Environment
If you are moving a project between servers, follow these steps to ensure all dependencies are perfectly matched:
- Open your terminal and navigate to your project folder.
- Generate a requirements list from your source machine:
pip freeze > requirements.txt - Transfer the file to your new Linux server.
- Verify connectivity by ensuring your Ubuntu IP address has internet access to reach PyPI.
- Install all dependencies at once using the list:
pip install -r requirements.txt - Confirm success by running
pip listto see the new libraries active on the destination.
Summary Tables
| Goal | Pip Command | Key Result |
|---|---|---|
| Install | pip install <name> | Downloads and installs a package. |
| Upgrade | pip install --upgrade <name> | Updates an existing package. |
| Remove | pip uninstall <name> | Deletes a library from the disk. |
| Audit | pip list | Shows all installed software versions. |
| Details | pip show <name> | Displays metadata and file paths. |
| Flag | Meaning | Use Case |
|---|---|---|
| -r | Requirements | Installing from a text list. |
| -U | Upgrade | Moving to the newest version. |
| -h | Help | Viewing all available flags. |
| -v | Verbose | Seeing detailed download progress. |
FAQs
What is the difference between pip and pip3? On most modern Linux distributions, pip may refer to Python 2, while pip3 is explicitly for Python 3. Since Python 2 is end-of-life, it is recommended to use pip3 unless your environment is specifically alias-configured.
Can I install a specific version of a package? Yes. You can use the double-equals syntax: pip install requests==2.28.0. This is vital for maintaining application stability.
How do I fix “command not found: pip”? This means pip is not installed on your system. You can install it using your system package manager. For example, on Ubuntu: sudo apt install python3-pip.
Related Posts
- Learn Python Pip in Two Minutes
- 3 Ways to Check Python 3 Version
- How To Check File Size in Linux
- Understanding Linux Commands: A Comprehensive Guide


