PIP (Python Package Installer) is the standard package manager for Python that enables you to install and manage additional libraries and dependencies that aren’t part of the Python Standard Library. It allows you to access thousands of packages created by the Python community. Instead of writing complex code from scratch, you can leverage existing packages to accelerate your development process.
Installation
Checking PIP Version
pip --version
Installing PIP
For Python 2.x:
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
For Python 3.x:
sudo yum install python3 python3-wheel
Essential PIP Commands
1. Installing Packages
Basic installation:
pip install package-name
Install specific version:
pip install package-name==version
Example:
pip install pyyaml==5.4.1
2. Package Information
View package details:
pip show package-name
Example output:
Name: PyYAML
Version: 5.4.1
Summary: YAML parser and emitter for Python
Home-page: https://pyyaml.org/
Author: Kirill Simonov
License: MIT
Location: /usr/local/lib64/python3.6/site-packages
3. Managing Packages
List all installed packages:
pip list
Check outdated packages:
pip list --outdated
Uninstall a package:
pip uninstall package-name
Best Practices
- Always verify package compatibility with your Python version
- Use virtual environments to isolate project dependencies
- Keep a requirements.txt file for your project dependencies
- Regularly update packages to receive security fixes and new features
- Consider using
pip-compile
for dependency management in production
Common Issues and Solutions
- If you encounter permission errors, use
--user
flag or virtual environments - For SSL certificate errors, ensure your certificates are up to date
- When facing version conflicts, consider using virtual environments