The fastest way: pip install from the command line
To install a Python package, open your terminal or command prompt and type pip install package_name, replacing package_name with the actual name of the package you want. Press Enter, and pip (Python's package installer) downloads and installs it for you.
For example, to install the popular data analysis library pandas, you would type:
pip install pandas
That's the complete process for most packages. Pip handles finding the package on PyPI (the Python Package Index), downloading the correct version for your system, and putting it in the right location so Python can find it when you write code.
Key Takeaways
- Use pip install package_name in your terminal to install almost any Python package in seconds.
- Check that Python and pip are installed first by typing python --version and pip --version in your terminal.
- If pip is not found, you may need to use pip3 instead, or reinstall Python with pip included.
- You can install a specific version of a package by typing pip install package_name==1.2.3 (replace 1.2.3 with the version number).
- Virtual environments keep packages for different projects separate, preventing conflicts between versions.
Check that pip is installed and working
Before you install anything, verify that pip is on your system. Open your terminal (on Mac or Linux) or Command Prompt (on Windows) and type:
pip --version
If you see a version number like "pip 23.1.2 from /usr/local/lib/python3.11/site-packages/pip", pip is installed and ready. If you see "command not found" or "pip is not recognized", pip is either not installed or not in your system's path.
On some systems, especially newer Macs and Linux machines, you may need to use pip3 instead of pip. Try pip3 --version to check. If that works, use pip3 install for all your installations.
Install Python and pip if you don't have them
If neither pip nor pip3 works, you need to install Python. Go to python.org, download the latest version for your operating system, and run the installer. On Windows, make sure to check the box that says "Add Python to PATH" during installation — this lets your terminal find Python and pip.
On Mac, you can also use Homebrew: type brew install python3 in your terminal. On Linux, use your package manager: apt install python3-pip on Ubuntu or Debian, or yum install python3-pip on Fedora or CentOS.
After installation, close and reopen your terminal, then run pip --version again to confirm it works.
Use a virtual environment to keep projects separate
A virtual environment is a folder on your computer that holds packages just for one project. This prevents version conflicts — for example, if one project needs pandas 1.3 and another needs pandas 2.0, a virtual environment lets each have its own copy.
To create a virtual environment, navigate to your project folder in the terminal and type:
python -m venv env
This creates a folder called env (you can name it anything). To activate it, type:
On Mac or Linux: source env/bin/activate
On Windows: env\Scripts\activate
Your terminal prompt will change to show the environment is active. Now when you type pip install package_name, packages go into this environment only, not your whole system. When you're done working, type deactivate to exit the environment.
Install a specific version of a package
By default, pip install package_name installs the latest version. If you need a different version — because your code was written for an older one, or because a newer version has a bug — you can specify it.
Type pip install package_name==1.2.3, replacing 1.2.3 with the version number you want. For example, pip install numpy==1.21.0 installs that exact version of numpy.
You can also use pip install package_name>=1.2.0 to install version 1.2.0 or any newer version, or pip install package_name<2.0 to install any version before 2.0. These are useful when you want some flexibility but need to avoid a version you know is broken.
Troubleshoot common installation problems
If you get an error like "No module named pip", your Python installation is incomplete. Reinstall Python from python.org and make sure to check "Add Python to PATH" on Windows, or use Homebrew or your Linux package manager on Mac and Linux.
If you see "ERROR: Could not find a version that satisfies the requirement", the package name is wrong or doesn't exist. Check the spelling on pypi.org — the official Python package repository. Package names are case-sensitive and sometimes use hyphens or underscores in unexpected places.
If installation starts but then fails with a compiler error, the package contains code that needs to be compiled for your system. You may need to install build tools: on Windows, install Microsoft C++ Build Tools; on Mac, install Xcode Command Line Tools by typing xcode-select --install; on Linux, install build-essential with your package manager.
If you get a permission error on Mac or Linux, do not use sudo to force installation. Instead, use a virtual environment (see above) or reinstall Python with Homebrew, which avoids permission issues.
See what packages you have installed
To list all packages in your current environment, type:
pip list
This shows the package name and version number for everything installed. To save this list to a file (useful for sharing your project or recreating the environment later), type:
pip freeze > requirements.txt
This creates a file called requirements.txt with every package and version. Someone else can then type pip install -r requirements.txt to install all the same packages at the same versions.
Frequently Asked Questions
What's the difference between pip and pip3?
On systems with both Python 2 and Python 3 installed, pip usually refers to Python 2 (which is no longer supported) and pip3 refers to Python 3. If you only have Python 3, pip and pip3 do the same thing. Use whichever one works on your system.
Can I install multiple packages at once?
Yes. Type pip install package1 package2 package3 to install several packages in one command. You can also list them in a requirements.txt file and type pip install -r requirements.txt to install them all.
What happens if I install a package that conflicts with one I already have?
Pip will warn you if a new package needs a different version of something already installed, but it may still install and break your code. This is why virtual environments are useful — each project gets its own set of packages without affecting others.
Do I need to restart Python after installing a package?
If Python is already running (in a terminal or IDE), yes — close and reopen it so it loads the newly installed package. If you're installing from the command line before you start Python, you don't need to restart anything.
Where do packages actually go when I install them?
Without a virtual environment, they go into your Python installation folder (usually something like /usr/local/lib/python3.11/site-packages on Mac/Linux or C:\Users\YourName\AppData\Local\Programs\Python\Python311\Lib\site-packages on Windows). With a virtual environment, they go into the env folder you created.