pip
pip is the package installer for Python. It allows you to install and manage additional libraries and dependencies that are not included in the Python standard library.
Installation and Basic Usage
-
Install a Package:
-
Uninstall a Package:
-
Check Installed Packages:
-
Check for Package Updates:
Managing Dependencies
-
Install from
requirements.txt
: Create arequirements.txt
file with a list of packages and versions:Install dependencies:
-
Freeze Installed Packages: Generate a
requirements.txt
file from the current environment: -
Upgrade a Package:
Environment and Compatibility
-
Create a Virtual Environment: Although
pip
itself doesn’t create virtual environments, it works seamlessly withvenv
orvirtualenv
. -
Activate the Virtual Environment:
-
On Windows:
-
On macOS/Linux:
-
-
Check pip Version:
-
Upgrade
pip
:
Scripting and Automation
-
Install Multiple Packages in a Single Command:
-
Automate Package Installation: Use shell scripts or batch files to automate installation in multiple environments.
Other
In pip, the concept of "development" dependencies (i.e., packages needed only for development, not for production) is not directly supported in the same way as some other tools like Poetry or Pipenv. However, you can manage development dependencies in a few ways using pip:
-
Using
requirements.txt
with Separate FilesYou can maintain separate
requirements.txt
files for different environments, such as one for production and one for development.Production
requirements.txt
:-
List only the packages required for your application to run in production
Development
requirements-dev.txt
:-
List the additional packages needed for development, such as testing and linting tools.
To install production dependencies:
To install development dependencies:
Alternatively, you can include development dependencies in a single file with markers or comments, and install them conditionally.
-