What pip does and when you use it

Pip is the standard tool for downloading and installing Python packages from PyPI (the Python Package Index), a central repository where developers publish code libraries. When you want to add functionality to Python — whether that's a web framework like Django, a data tool like NumPy, or a testing library — pip fetches the package and installs it on your computer so your Python code can use it.

Pip comes built into Python 3.4 and later, so if you have Python installed, you likely have pip already. You run pip from your command line (Terminal on Mac, Command Prompt on Windows, or a terminal on Linux) to install, update, or remove packages. Unlike some package managers that require separate setup, pip works immediately after Python installation.

Most Python developers use pip for every project because it's simple, widely supported, and handles dependencies automatically — if the package you want needs other packages to work, pip installs those too.

Key Takeaways

  • Pip comes with Python 3.4 and later, so check if you have it by running pip --version in your terminal.
  • The basic command to install a package is pip install package-name, and pip downloads it from PyPI and sets it up for you.
  • Virtual environments let you install packages for one project without affecting others, and you should create one before installing packages for any real work.
  • You can install specific versions, multiple packages at once, or packages listed in a requirements file using different pip commands.
  • Pip stores installed packages in a site-packages folder that Python checks automatically when you import code.

Check if pip is installed and working

Open your terminal or command prompt and type pip --version. If pip is installed, you'll see output like pip 23.1.2 from /usr/local/lib/python3.11/site-packages/pip (python 3.11). The exact version and path 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 is not recognized" or "command not found", pip either isn't installed or isn't in your system's PATH. On Windows, try py -m pip --version instead. On Mac or Linux, you may need to use pip3 instead of pip if you have both Python 2 and Python 3 installed (Python 2 is no longer supported, but some older systems still have it). If neither works, reinstall Python and make sure to check the box that says "Add Python to PATH" during installation.

Create a virtual environment before installing packages

A virtual environment is a separate folder on your computer where pip installs packages just for one project. This prevents different projects from conflicting — if Project A needs version 1.0 of a library and Project B needs version 2.0, a virtual environment lets each have its own copy. For any real work, create a virtual environment first.

Navigate to your project folder in the terminal, then run python -m venv env (on Windows) or python3 -m venv env (on Mac or Linux). This creates a folder called env that holds everything for this project's environment. Then activate it by running env\Scripts\activate on Windows, or source env/bin/activate on Mac or Linux. You'll see (env) appear at the start of your terminal prompt, showing the environment is active.

Once activated, any pip install command you run will put packages into this environment only. When you're done working, type deactivate to exit the environment. The next time you work on that project, activate it again with the same command.

Install a single package

With your virtual environment activated (or without one if you're just testing), run pip install package-name, replacing package-name with the actual name. For example, pip install requests installs the Requests library, which is used for making web requests. Pip downloads the package from PyPI, installs it, and also installs any other packages it depends on.

The terminal will show progress as it downloads and installs. When it finishes, you'll see a success message. You can now use that package in your Python code by typing import requests at the top of your script. If you're not sure of the exact package name, search PyPI.org in your browser — the URL for each package shows the correct name to use with pip.

Install a specific version or multiple packages

To install a particular version of a package, use pip install package-name==1.2.3, where 1.2.3 is the version number. For example, pip install django==4.2.0 installs Django version 4.2.0 specifically. You can also use >= or <= to install a version within a range: pip install django>=4.0 installs version 4.0 or any newer version available.

To install multiple packages at once, list them separated by spaces: pip install requests flask numpy. Pip will install all three and their dependencies. For larger projects with many packages, create a requirements.txt file in your project folder with one package name per line (you can add versions too, like django==4.2.0), then run pip install -r requirements.txt. This installs everything listed in that file, which is useful for sharing your project with others or setting it up on a different computer.

Update or remove packages

To update a package to the latest version, run pip install --upgrade package-name or the shorter pip install -U package-name. Pip will check PyPI, find the newest version, and install it over the old one. To remove a package you no longer need, run pip uninstall package-name. Pip will ask for confirmation before deleting it.

To see what packages you have installed in your current environment, run pip list. This shows the package name and version for everything. If you want to save this list so you can recreate the same environment later, run pip freeze > requirements.txt. This creates a requirements.txt file with exact versions of every package, which you can share or use to set up the same environment on another machine.

Understand where pip puts packages

When you install a package, pip stores it in a folder called site-packages. If you're using a virtual environment, this folder is inside your env folder. If you're installing globally (without a virtual environment), it goes to your Python installation's site-packages folder, which is why virtual environments are important — they keep projects separate.

When you write import package-name in your Python code, Python automatically looks in site-packages to find it. You don't need to tell Python where the package is; pip handles that by putting it in the right place. This is why pip is easier than manually downloading and organizing code files.

Frequently Asked Questions

What's the difference between pip and pip3?

On systems with both Python 2 and Python 3 installed, pip usually points to Python 2 (which is no longer supported) and pip3 points to Python 3. If you only have Python 3 installed, pip and pip3 do the same thing. To be safe, use pip3 on Mac or Linux, or py -m pip on Windows.

Can I use pip to install packages from somewhere other than PyPI?

Yes. You can install from a GitHub repository using pip install git+https://github.com/user/repo.git, or from a local file using pip install /path/to/package. Most of the time you'll use PyPI, but pip supports other sources if you need them.

What does "pip install" do if the package is already installed?

If the package is already installed, pip checks the version. If you didn't specify a version and a newer one exists, pip upgrades it. If you specified an exact version and it's already there, pip does nothing. This makes it safe to run the same install command multiple times.

Why do I get a permission error when installing packages?

This usually means you're trying to install globally without permission. The fix is to use a virtual environment, which doesn't require special permissions. If you must install globally, avoid using sudo with pip — instead, use pip install --user package-name to install in your user folder.

How do I know what packages are available on PyPI?

Visit PyPI.org and search for what you need. Each package page shows the correct name to use with pip, the latest version, documentation, and often a link to the source code. You can also run pip search keyword from the terminal, though this feature is disabled on many systems for performance reasons.