How to Install a Python Package with pip

Learn how to install Python packages with pip, check that pip works, and fix the most common installation problems. This page focuses on the basic command-line steps beginners need.

Quick command

python -m pip install requests

Use python -m pip if pip does not work by itself. Replace requests with the package name you want to install.

What this page helps you do

This page shows you how to:

  • Install a package from the command line
  • Use the safest beginner-friendly pip command
  • Check that the package installed correctly
  • Fix common pip install problems

What pip is

pip is Python's package installer.

A package is extra code you can add to Python. For example, the requests package helps you work with web requests without writing everything from scratch.

You use pip to download and install packages like requests, numpy, and many others.

If you are new to modules and packages, see Python modules explained.

Check that Python and pip work

Before installing anything, make sure Python and pip are available in your terminal.

Run:

python --version

You should see a Python version, such as:

Python 3.12.2

Then check pip:

python -m pip --version

You should see output similar to this:

pip 24.0 from ...

If python does not work, install Python first. If python -m pip --version works, you can use pip through Python even if the plain pip command fails.

Install a package with pip

The basic command is:

python -m pip install package_name

Replace package_name with the real package name.

Example:

python -m pip install requests

Wait for the installation to finish before closing the terminal.

If the install works, you will usually see messages showing that the package was downloaded and installed.

Install a specific version

Sometimes a tutorial or project needs one exact version of a package.

Use == to choose a version:

python -m pip install requests==2.31.0

This tells pip to install version 2.31.0 and not a newer one.

This is useful when:

  • A tutorial was written for a specific version
  • Your project depends on a known version
  • A newer version causes problems

Upgrade a package

To upgrade an installed package to a newer version, use --upgrade:

python -m pip install --upgrade requests

This tells pip to update the package if a newer version is available.

Check that the package is installed

There are two simple ways to check.

Option 1: Show package information

Run:

python -m pip show requests

If the package is installed, pip will show information such as its name, version, and install location.

Option 2: Import the package in Python

You can also test the package directly.

import requests

print(requests.__version__)

If the import works, the package is installed for that Python environment.

You can also test it from the command line:

python -c "import requests; print(requests.__version__)"

If you need help with imports, see how to import a module in Python.

Use pip in a virtual environment

A virtual environment keeps project packages separate from other Python projects on your computer.

This helps you avoid version conflicts and keeps your project cleaner.

The basic idea is:

  1. Create a virtual environment
  2. Activate it
  3. Install packages inside it

After activation, install packages the same way:

python -m pip install requests

Using a virtual environment is the best choice for real projects. For step-by-step setup, see how to create and use a virtual environment in Python.

Common pip install errors

Here are the most common problems beginners run into.

pip command not found

This usually means:

  • pip is not on your system path
  • You are using the wrong command
  • Python may not be installed correctly

Try this instead:

python -m pip --version

If that works, keep using python -m pip instead of plain pip.

You can also check which Python and pip your terminal is using.

On Windows:

where python
where pip

On macOS or Linux:

which python
which pip

Installed package in a different Python version

This is very common.

You may have installed a package with one Python installation, but your code is running with another one.

Check:

python --version
python -m pip --version

These commands should point to the same Python installation you use to run your code.

Permission denied when installing

This usually happens when you try to install packages globally without permission.

Instead of forcing a global install, it is usually better to use a virtual environment. That keeps your project isolated and avoids permission problems.

Module still not found after install

If you installed a package but still get an import error, the package may be in the wrong environment.

For example, this error:

import requests

might produce:

ModuleNotFoundError: No module named 'requests'

This usually means one of these:

  • The package was installed into a different Python version
  • Your virtual environment is not active
  • The package name was typed incorrectly

For more help, see ModuleNotFoundError: No module named x and ImportError: No module named x.

Beginner tips

These simple habits prevent many installation problems:

  • Prefer python -m pip over pip when possible
  • Make sure your terminal uses the same Python as your project
  • Copy the package name exactly
  • Install inside a virtual environment for real projects

Common mistakes

These are the most common causes of pip problems:

  • Using pip for a different Python installation
  • Typing the package name incorrectly
  • Forgetting to activate a virtual environment
  • Trying to install without permission
  • Using pip when pip is not on the system path

Useful debugging commands:

python --version
python -m pip --version
python -m pip install requests
python -m pip show requests
python -c "import requests; print(requests.__version__)"

On Windows:

where python
where pip

On macOS or Linux:

which python
which pip

FAQ

Should I use pip or python -m pip?

For beginners, python -m pip is usually safer because it uses pip from that Python installation.

Why does Python say ModuleNotFoundError after I installed the package?

You may have installed the package into a different Python version or environment than the one running your code.

Do I need administrator or sudo access?

Not always. It is usually better to use a virtual environment instead of installing globally.

How do I install a specific version of a package?

Use:

python -m pip install package_name==version_number

Example:

python -m pip install requests==2.31.0

See also