What pip does and why you need it
Pip is the tool that downloads and installs Python packages — the pre-written code libraries that do specific jobs so you don't have to write them from scratch. When you want to use a package like Django (for building websites) or Requests (for fetching data from the internet), pip is what fetches it from the internet and puts it where Python can find it.
Pip comes built into Python on most systems. If you installed Python 3.4 or later, you already have pip. It lives on your computer as a command you run in your terminal or command prompt — the same place where you type other instructions to your machine.
Key Takeaways
- Pip is already installed if you have Python 3.4 or later, and you run it from your terminal by typing commands, not by clicking.
- The basic command is pip install package-name, where you replace package-name with the actual name of what you want — like pip install django.
- Virtual environments (created with python -m venv folder-name) keep each project's packages separate so they don't conflict with each other.
- You can install multiple packages at once or from a requirements file, which lists all the packages a project needs.
- If pip isn't found when you type the command, you may need to use python -m pip instead, or reinstall Python with pip included.
Checking whether pip is installed on your machine
Open your terminal (on Mac or Linux) or Command Prompt (on Windows). Type this exactly:
pip --version
If pip is installed, you'll see a line that says something like pip 23.1.2 from /usr/local/lib/python3.11/site-packages/pip (python 3.11). The exact numbers don't matter — you just need to see that pip exists and which Python version it's tied to.
If you see an error like "pip: command not found" or "pip is not recognized", skip to the troubleshooting section below.
Installing a single package with pip
The basic command is straightforward. In your terminal, type:
pip install package-name
Replace package-name with the actual name of the package you want. For example, to install Django, you would type:
pip install django
Pip will read the package and any other packages it depends on, then install them all. You'll see lines of text showing the read progress. When it's done, you'll see a line that says "Successfully installed" followed by the package name and version number.
You can now use that package in your Python code by writing import django at the top of your file.
Using virtual environments to keep projects separate
If you work on multiple Python projects, you should use a virtual environment for each one. A virtual environment is a folder on your computer that holds its own copy of Python and its own set of installed packages. This way, if one project needs version 2.0 of a package and another needs version 3.0, they won't fight each other.
To create a virtual environment, navigate to your project folder in the terminal and type:
python -m venv venv
This creates a folder called venv inside your project. Now set up it. On Mac or Linux, type:
source venv/bin/set up
On Windows, type:
venv\Scripts\set up
You'll see the word (venv) appear at the start of your terminal prompt. Now when you run pip install, it installs packages into this project's virtual environment only, not into your whole computer. When you're done working, type deactivate to turn off the virtual environment.
Installing multiple packages and using requirements files
If you need to install several packages at once, you can list them on one line:
pip install django requests beautifulsoup4
For larger projects, create a file called requirements.txt in your project folder. List each package on its own line, like this:
django==4.2 requests==2.31.0 beautifulsoup4==4.12.0
Then install everything in that file with one command:
pip install -r requirements.txt
The numbers after the package names are version numbers. If you want a specific version, include it. If you just want the latest version, leave the version number out and pip will fetch whatever is newest.
Troubleshooting when pip isn't found
If you got an error when you checked the version, try this command instead:
python -m pip --version
If that works, use python -m pip instead of pip for all your commands. So instead of pip install django, you would type python -m pip install django.
If neither command works, Python may not have been installed with pip included. Reinstall Python from python.org and make sure the checkbox that says "Add Python to PATH" (Windows) or follow the default installation (Mac/Linux) is selected. Then restart your terminal and try again.
On some systems, you may need to use pip3 instead of pip if you have both Python 2 and Python 3 installed. Try pip3 install package-name.
Updating and removing packages
To update a package to its newest version, type:
pip install --upgrade package-name
Or the shorter version:
pip install -U package-name
To remove a package you no longer need, type:
pip uninstall package-name
Pip will ask you to confirm before deleting it. To see all the packages you have installed in your current environment, type:
pip list
Frequently Asked Questions
Why do I need a virtual environment if I'm just learning?
Virtual environments prevent conflicts when you work on multiple projects. If you only ever work on one project, you can skip them for now. But as soon as you start a second project, create a virtual environment for it so the packages don't interfere with each other.
What's the difference between pip and conda?
Conda is another package manager that does the same job as pip but comes with Anaconda, a different Python distribution. Pip is the standard for most Python projects. Unless you're specifically using Anaconda, use pip.
Can I install a package from somewhere other than the internet?
Yes. You can install from a local file with pip install /path/to/file.whl or from a GitHub repository with pip install git+https://github.com/user/repo.git. But the default behavior — installing from the Python Package Index — is what you'll use most of the time.
What does the error "No module named pip" mean?
It means Python can't find pip. Try using python -m pip instead of pip. If that doesn't work, pip wasn't installed with your Python version and you'll need to reinstall Python.
How do I know what version of a package to install?
You can see all available versions on pypi.org by searching for the package name. If you don't specify a version, pip installs the latest one. For learning, the latest version is usually fine. For production code, pin specific versions in your requirements file so updates don't break your code unexpectedly.