pip
pip
is the package installer for Python, allowing you to install and manage additional libraries and dependencies that are not part of the Python standard library.
Download get-pip.py:
Install pip
:
get-pip.py
.python get-pip.py
pip --version
Ensure Python is installed:
brew
to install the latest version./bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
Install pip
:
pip
is included with Python installations via Homebrew. Verify the installation by running:
pip3 --version
Ensure Python is installed:
python3 --version
Install pip
:
sudo apt update
sudo apt install python3-pip
sudo yum install python3-pip
pip3 --version
Using a virtual environment is a good practice to manage dependencies for different projects separately.
Navigate to your project directory:
cd /path/to/your/project
Create a virtual environment:
python3 -m venv venv
This command creates a new directory named venv
containing the virtual environment.
Windows:
venv\Scripts\activate
macOS and Linux:
source venv/bin/activate
You should see the name of your virtual environment in the terminal prompt, indicating that the virtual environment is active.
To deactivate the virtual environment, simply run:
deactivate
Dependencies for a project are typically listed in a requirements.txt
file.
requirements.txt
FileTo generate a requirements.txt
file for your project, run:
pip freeze > requirements.txt
This command lists all the installed packages and their versions and saves them to requirements.txt
.
requirements.txt
To install the dependencies listed in requirements.txt
, ensure your virtual environment is activated, then run:
pip install -r requirements.txt