PIP
Overview of the Standard Python Package Manager, PIP.
Introduction
The standard Python package manager is pip
. It is ideal for quickly starting Python projects, like simple scripts or small projects with few dependencies. While capable of handling larger projects, tools like poetry
are ideal for larger projects with complex dependencies.
The following notes assume:
Python 3
MacOS
An alias in
bash
profile to mappython
topython3
.
Setup
The following is a step-by-step process for setting up a virtual environment in my-project
and installing dependencies in it with pip
.
cd
into your project directory.
cd my-project
Create the virtual environment named
env
.
python -m venv env
Activate the virtual environment.
source env/bin/activate
Install dependencies.
pip install <PACKAGE_NAME>
Commands
The following is a list of common commands used when managing a project with pip
.
Activate Virtual Environment
source env/bin/activate
Deactivate Virtual Environment
deactivate
Uninstall a Package
pip uinstall <PACKAGE_NAME>
List Installed Packages
pip freeze
Create a requirements.txt File
pip freeze > requirements.txt
Install Packages from a requirements.txt File
pip install -r requirements.txt
Pitfalls & Solutions
The following are common pitfalls when working with pip
and their solutions.
Last updated
Was this helpful?