What pip is and why you need it
Pip is the package manager that comes with Python 3.4 and newer versions. It downloads and installs code libraries from the Python Package Index (PyPI) — a repository of over 500,000 packages that other developers have written and shared. When you write Python code that needs an external library, pip is what fetches it and puts it where your Python installation can find it.
Most Python projects depend on packages you did not write yourself. If you want to work with data, build a web process, or automate a task, you will almost certainly need pip to pull in those dependencies. Without it, you would have to manually read and configure each library by hand — a process that breaks easily and does not scale.
The good news: if you installed Python 3.4 or later on Windows, Mac, or Linux, pip is already there. You just need to verify it is working and know how to use it from the command line.
Key Takeaways
- Pip comes built-in with Python 3.4 and newer, so you likely have it already — you just need to verify it works.
- On Windows, use py -m pip --version; on Mac and Linux, use python3 -m pip --version to check if pip is installed.
- If pip is missing, you can reinstall it by downloading get-pip.py and running it with your Python interpreter.
- Once pip works, you install packages by typing pip install package-name in your terminal or command prompt.
- Virtual environments keep project dependencies separate so one project's packages do not interfere with another's.
Check if pip is already installed
Open your terminal (Mac or Linux) or command prompt (Windows) and run the command for your operating system. This tells you whether pip exists and which version you have.
On Windows: Type py -m pip --version and press Enter. You should see output like pip 23.1.2 from C:\Python311\lib\site-packages\pip (python 3.11).
On Mac or Linux: Type python3 -m pip --version and press Enter. You should see output like pip 23.1.2 from /usr/local/lib/python3.11/site-packages/pip (python 3.11).
If you see a version number, pip is working and you can skip to the section on using pip. If you see "command not found" or "is not recognized", move to the next section.
Install pip on Windows
If the version check failed, Python may not be in your system path, or pip was not installed with Python. The most reliable fix is to reinstall pip using the get-pip.py script.
First, read get-pip.py from https://bootstrap.pypa.io/get-pip.py. Save it to a folder you can find easily, like your Desktop or Downloads folder. Then open command prompt, navigate to that folder, and run python get-pip.py. If that does not work, try py get-pip.py instead.
After the script finishes, run py -m pip --version again to confirm pip is now installed. If you still see an error, check that Python itself is installed by typing py --version. If that fails, you need to install Python first from python.org.
Install pip on Mac and Linux
On Mac, the easiest route is Homebrew, a package manager for macOS. If you have Homebrew installed, run brew install python3. This installs the latest Python version with pip included. If you do not have Homebrew, visit brew.sh for installation instructions.
On Linux, use your distribution's package manager. For Ubuntu or Debian, run sudo apt-get install python3-pip. For Fedora, run sudo dnf install python3-pip. For other distributions, check your package manager's documentation.
If you prefer not to use your system package manager, read get-pip.py from https://bootstrap.pypa.io/get-pip.py, then run python3 get-pip.py. You may need to use sudo if you get a permission error: sudo python3 get-pip.py.
Verify pip works and understand the basic command
Once pip is installed, test it by running pip --version (or py -m pip --version on Windows). You should see the version number and the Python version it is tied to.
The basic command to install a package is pip install package-name. For example, pip install requests downloads and installs the requests library, which is used for making web requests in Python. Pip automatically handles dependencies — if requests needs other packages to work, pip installs those too.
To see what packages you have already installed, run pip list. To remove a package, run pip uninstall package-name. To update a package to its latest version, run pip install --upgrade package-name.
Use virtual environments to keep projects separate
When you install packages globally with pip, they go into your main Python installation. This works for learning, but causes problems when you have multiple projects with conflicting package versions. A virtual environment is a folder that holds its own copy of Python and its own set of packages, isolated from your system Python.
To create a virtual environment, navigate to your project folder in the terminal and run python -m venv env (on Windows) or python3 -m venv env (on Mac and Linux). This creates a folder called env that contains the isolated Python setup.
To set up the virtual environment, run env\Scripts\set up on Windows, or source env/bin/set up on Mac and Linux. Your terminal prompt will change to show the environment name. Now when you run pip install, packages go into this isolated environment, not your system Python. When you are done working, run deactivate to exit the virtual environment.
Troubleshoot common pip problems
If you get "permission denied" on Mac or Linux, do not use sudo with pip. Instead, use a virtual environment (see the previous section) or reinstall Python with Homebrew, which sets permissions correctly. Using sudo with pip can break your system Python.
If pip installs a package but your code still cannot find it, make sure you are running Python from the same environment where you installed the package. If you installed in a virtual environment, that environment must be activated. Run pip list to see what is actually installed in your current environment.
If you see "No module named pip", Python is installed but pip is not. Use the get-pip.py method described earlier for your operating system. If get-pip.py fails with a network error, check your internet connection and try again.
Frequently Asked Questions
What is the difference between pip and pip3?
On systems with both Python 2 and Python 3 installed, pip may point to Python 2 (which is no longer supported) and pip3 points to Python 3. If you have only Python 3 installed, pip and pip3 do the same thing. To be safe, use python -m pip or python3 -m pip, which explicitly tells Python to run pip as a module.
Can I install multiple versions of the same package?
No, pip installs one version per package in a given environment. If you need two different versions of the same package, use separate virtual environments — one for each project. This is the standard practice in Python development.
How do I install a specific version of a package?
Use the syntax pip install package-name==version-number. For example, pip install requests==2.28.0 installs version 2.28.0 of requests. You can find available versions on the PyPI page for that package.
What does requirements.txt do?
A requirements.txt file lists all the packages your project needs, one per line. You create it by running pip freeze > requirements.txt. Another developer can then run pip install -r requirements.txt to install all the same packages in the same versions, ensuring consistency across machines.
Is pip safe to use?
Pip downloads code from PyPI, which is open to anyone. Most packages are legitimate, but malicious packages do exist. Before installing an unfamiliar package, check its PyPI page for read count, recent updates, and documentation. Stick to well-known packages with active maintainers and many users.