The fastest way to install a Python library is through pip, Python's built-in package manager

When you install Python on your computer, pip comes with it automatically. To install a library, you open your command line (Terminal on Mac, Command Prompt on Windows) and type a single command. The library downloads and installs in seconds. Most of the time, this is all you need to do.

The command always follows the same pattern: pip install library-name. For example, to install a library called requests, you would type pip install requests and press Enter. Python finds the library on its official repository, downloads it, and sets it up so your code can use it immediately.

The main reason this process fails is that your computer cannot find pip, usually because Python was not installed correctly or your system does not know where to find it. The second most common problem is typing the library name wrong — library names are case-sensitive and often use hyphens instead of underscores.

Key Takeaways

  • Open your command line and type pip install library-name, replacing library-name with the actual name of the library you want.
  • Check that Python is installed first by typing python --version in your command line — you should see a version number like 3.9 or 3.11.
  • If pip is not found, reinstall Python and make sure to check the box that says "Add Python to PATH" during installation.
  • Library names on the official Python Package Index (PyPI) are the correct names to use — search PyPI if you are unsure of the exact spelling.

Check that Python and pip are installed on your system

Before you install any library, confirm that Python itself is on your computer and that pip came with it. Open your command line — on Windows, search for "Command Prompt" in the Start menu; on Mac, open Applications, then Utilities, then Terminal.

Type this command and press Enter: python --version. If Python is installed, you will see a version number like Python 3.11.0. If you see "python is not recognized" or "command not found", Python is not installed or your system cannot find it. In that case, download Python from python.org, run the installer, and make sure to check the box labeled "Add Python to PATH" before clicking Install.

Once Python is installed, check pip by typing pip --version. You should see something like pip 23.0 from /path/to/python/lib. If pip is not found but Python is, your Python installation may be incomplete — reinstall Python and select the full installation option.

Install a library using the basic pip command

The standard way to install a library is to type pip install library-name in your command line. Replace library-name with the actual name of the library. For instance, to install the requests library (used for downloading web pages), type pip install requests and press Enter.

Your command line will show a series of messages as pip downloads and installs the library. You will see lines like "Collecting requests" and "Installing collected packages: requests". When it finishes, you will see a message like "Successfully installed requests-2.28.1" or similar. The library is now ready to use in your Python code.

If you see an error message like "ERROR: Could not find a version that satisfies the requirement", the library name is spelled wrong or does not exist. Check the spelling against the official Python Package Index at pypi.org. If you see "ERROR: Could not install packages due to an EnvironmentError", your system may not have permission to install — try typing pip install --user library-name instead, which installs the library only for your user account.

Find the correct library name when you are unsure

Library names are not always obvious. The library you want might be called something different than you expect, or it might use hyphens instead of underscores. The official source for library names is the Python Package Index at pypi.org.

Go to pypi.org and use the search box at the top to search for what you need. For example, if you want to work with Excel files, search for "excel" and you will see libraries like openpyxl, xlrd, and pandas. Each library has its own page showing the exact name to use in your pip command, installation instructions, and documentation. Copy the name exactly as it appears on the PyPI page — this is the name you use in your pip install command.

Install a specific version of a library

Sometimes you need a particular version of a library because your code was written for that version, or because a newer version has a bug. You can install a specific version by adding ==version-number to your command.

For example, to install version 2.28.1 of the requests library, type pip install requests==2.28.1. To install the latest version that is 2.28 or older, type pip install requests==2.28.*. To install version 2.28 or any newer version, type pip install requests>=2.28.

You can see all available versions of a library on its PyPI page. Scroll down to the "Release history" section to see every version that has been released. Most of the time, you should install the latest version unless you have a specific reason not to.

Upgrade a library you already have installed

If a library is already on your computer but you want the newest version, use the --upgrade flag. Type pip install --upgrade library-name or the shorter form pip install -U library-name.

For example, to upgrade the requests library to the latest version, type pip install --upgrade requests. Pip will check what version you have, download the newest one, and replace the old version. Your existing code will usually work with the new version, but occasionally a major update changes how the library works — if your code breaks after an upgrade, you can downgrade to the previous version using the specific version command from the section above.

Troubleshoot the most common installation problems

If you see "pip is not recognized as an internal or external command", pip is not in your system's PATH. On Windows, reinstall Python and check the "Add Python to PATH" box. On Mac or Linux, you may need to use pip3 instead of pip — type pip3 install library-name.

If you see "ERROR: Could not install packages due to a PermissionError", your user account does not have permission to install system-wide. Add --user to your command: pip install --user library-name. This installs the library only for your account instead of for all users on the computer.

If the installation appears to hang or freeze, it may be downloading a large library or a dependency. Wait a few minutes before assuming it is stuck. If it truly does not respond after five minutes, press Ctrl+C to stop it, then try again.

If you install a library but your Python code still says "ModuleNotFoundError: No module named", make sure you are running Python from the same command line where you installed the library. Some systems have multiple Python installations, and pip may have installed the library for one version while you are running code with another. Type which python (Mac/Linux) or where python (Windows) to see which Python your system is using.

Frequently Asked Questions

What is the difference between pip and pip3?

On systems with both Python 2 and Python 3 installed, pip usually refers to Python 2 and pip3 refers to Python 3. Since Python 2 is no longer supported, you should use pip3 if your system has both versions. If you only have Python 3 installed, pip and pip3 do the same thing.

Can I install multiple libraries at once?

Yes. Type pip install library1 library2 library3, separating each name with a space. You can also create a text file called requirements.txt with one library name per line, then type pip install -r requirements.txt to install them all at once. This is useful when sharing code with others or setting up a new computer.

What happens if I install a library that conflicts with another library I already have?

Pip will warn you if a new library requires a different version of something you already have. Usually it will fix the conflict automatically by downgrading or upgrading the conflicting library. If it cannot resolve the conflict, it will stop and show you an error message explaining which libraries are incompatible.

Do I need to restart my computer after installing a library?

No. You do need to restart your Python program if it is already running — close it and run it again so it loads the newly installed library. You do not need to restart your computer or your code editor.

Where do installed libraries actually go on my computer?

Pip installs libraries in a folder called site-packages inside your Python installation directory. You do not need to know where this is — pip handles it automatically. If you want to see where it is, type python -m site in your command line and look for the USER_SITE or ENABLE_USER_SITE line.