Pip Basics
What is Pip?
Pip is the standard package management system for Python, allowing developers to easily install, upgrade, and manage Python libraries and dependencies. It simplifies the process of adding external modules to your Python projects.
Installation
On Ubuntu 22.04, pip typically comes pre-installed with Python. However, you can verify or install it using the following commands:
## Check pip version
python3 -m pip --version
## Install pip if not already present
sudo apt update
sudo apt install python3-pip
Core Functionality
Pip provides several key functions for package management:
Command |
Purpose |
pip install |
Install packages |
pip uninstall |
Remove packages |
pip list |
Show installed packages |
pip freeze |
Output installed packages in requirements format |
Package Installation Workflow
graph TD
A[Start] --> B{Package Selected?}
B --> |Yes| C[Run pip install]
B --> |No| D[Search PyPI]
C --> E[Download Package]
E --> F[Install Dependencies]
F --> G[Package Ready to Use]
Basic Usage Examples
## Install a specific package
pip install numpy
## Install a specific version
pip install pandas==1.3.0
## Install multiple packages
pip install requests scipy matplotlib
## Install from requirements file
pip install -r requirements.txt
Package Sources
Pip primarily downloads packages from PyPI (Python Package Index), the official third-party software repository for Python.
Best Practices
- Always use virtual environments
- Keep pip and packages updated
- Use
requirements.txt
for project dependencies
- Be cautious with global package installations
LabEx recommends practicing package management in isolated development environments to maintain system stability.