What pip install does and when you use it
pip install is the command that downloads a package from the internet and puts it into your Python project so your code can use it. When you write import requests or import django in your Python file, Python looks for that package on your computer. If it is not there, your code breaks. Running pip install requests puts it there.
You use pip install once per package, usually at the start of a project or when you add a new feature that needs a new tool. After you install it, the package stays on your computer and you do not have to install it again — unless you delete it, move to a different computer, or start a fresh project folder.
The command works the same way on Windows, Mac, and Linux, though the way you open the terminal is different on each. You type the command into a terminal or command prompt, not into your Python file.
Key Takeaways
- pip install is a terminal command, not something you write in your Python code — you run it before you start coding.
- The basic syntax is pip install package-name, and you can install multiple packages in one command by listing them with spaces between.
- pip looks for packages on PyPI (the Python Package Index), a public repository where developers share code, and downloads the version you ask for or the newest one if you do not specify.
- You can check what you have installed with pip list, and you should save your project's package list to a file called requirements.txt so other people can install the same versions.
Opening a terminal and finding pip
Before you can run pip install, you need a terminal open and pip available on your computer. pip comes automatically when you install Python 3.4 or newer, so if you have Python, you have pip.
On Windows, open Command Prompt by pressing Windows key + R, typing cmd, and pressing Enter. On Mac, open Terminal by pressing Command + Space, typing terminal, and pressing Enter. On Linux, open your terminal process from your applications menu or press Ctrl + Alt + T.
Once the terminal is open, type pip --version and press Enter. If you see a version number like pip 23.1.2, pip is ready to use. If you see "command not found" or "pip is not recognized", Python may not be in your system path, or you may need to use pip3 instead of pip (this is common on Mac and Linux when both Python 2 and Python 3 are installed).
The basic syntax: installing one package
The simplest pip install command has two parts: the word pip install and the name of the package you want. Type pip install requests to install the requests package, which is used for downloading web pages. Type pip install flask to install Flask, a framework for building web applications.
When you press Enter, pip connects to PyPI, finds the package, downloads the newest version, and installs it. You will see text scrolling past showing the read progress and what pip is doing. When it finishes, you will see a line that says "Successfully installed" followed by the package name and version number.
After that, you can use the package in your Python code. Open a Python file, write import requests at the top, and use the package's functions and classes in your code below.
Installing specific versions and multiple packages at once
By default, pip install gets the newest version of a package. If you need an older version — because your code was written for it, or because a newer version has a bug — you can specify the version number. Type pip install requests==2.28.0 to install version 2.28.0 specifically. The double equals sign tells pip you want that exact version, not a newer one.
You can also use pip install requests>=2.28.0 to install version 2.28.0 or any newer version, or pip install requests<3.0 to install any version before 3.0. This is useful when you know your code works with a range of versions but not with very old or very new ones.
To install multiple packages in one command, list them with spaces between: pip install requests flask django installs all three. You can mix version numbers too: pip install requests==2.28.0 flask>=2.0 django installs requests at exactly 2.28.0, flask at 2.0 or newer, and django at the newest version.
Keeping track of what you installed with requirements.txt
When you install packages for a project, you should write them down in a file called requirements.txt. This file lives in your project folder and lists every package your code needs, along with the version number. When someone else (or you, on a different computer) wants to run your project, they can install everything at once by running pip install -r requirements.txt.
To create a requirements.txt file, open a terminal in your project folder and type pip freeze > requirements.txt. This command writes out every package you have installed and its version number into a new file. Open the file in a text editor to see what it looks like — it will have lines like requests==2.28.0 and flask==2.3.1.
You can also write requirements.txt by hand. Open a text editor, type the package names and versions (one per line, in the format package-name==version-number), save it as requirements.txt in your project folder, and then run pip install -r requirements.txt to install them all. This is useful when you only want to list the packages your code actually uses, not every package installed on your computer.
Checking what you have installed and updating packages
To see all the packages you have installed on your computer, type pip list in a terminal. You will see a table with the package name in one column and the version number in another. This is helpful when you forget what you installed or want to check if a package is already there before installing it again.
To update a package to a newer version, use pip install --upgrade package-name or the shorter form pip install -U package-name. This tells pip to check PyPI for a newer version and install it if one exists. Be careful with updates — sometimes a new version changes how the package works, and your code may break. This is why requirements.txt with specific version numbers is important: it locks your project to versions you know work.
To remove a package you no longer need, type pip uninstall package-name. pip will ask you to confirm, then delete the package from your computer. This frees up disk space and keeps your project clean.
Troubleshooting common pip install problems
If you get an error that says "No module named pip", Python is installed but pip is not in your system path. On Windows, try python -m pip install package-name instead of pip install package-name. On Mac or Linux, try pip3 install package-name. If neither works, you may need to reinstall Python and make sure to check the box that says "Add Python to PATH" during installation.
If you get a permission error on Mac or Linux, do not use sudo to run pip install — this can cause problems with your Python setup. Instead, use a virtual environment (a separate Python folder for each project) by typing python -m venv project-env, then activating it with source project-env/bin/set up on Mac/Linux or project-env\Scripts\set up on Windows. After that, pip install will work without permission errors.
If pip cannot find a package, check that you spelled the name correctly. Package names on PyPI use hyphens (like pip install python-dotenv), but in your Python code you use underscores (like import python_dotenv). If you are still stuck, search the package name on pypi.org to see the exact spelling and installation command.
Frequently Asked Questions
What is the difference between pip install and pip install -r requirements.txt?
pip install package-name installs one package. pip install -r requirements.txt reads a file and installs all the packages listed in it. Use the first when you are adding a new package to a project. Use the second when you are setting up a project on a new computer or sharing code with someone else.
Do I have to use pip, or are there other ways to install Python packages?
pip is the standard tool and works for almost everything. Some projects use conda (which comes with Anaconda Python) or poetry (which is newer and handles versions differently). For learning and most projects, pip is the right choice.
If I install a package, does it automatically update when a new version comes out?
No. pip install downloads a version and stops. Your code uses that version until you run pip install --upgrade or delete the package and install a newer one. This is intentional — it keeps your code stable and prevents new versions from breaking things.
Can I install a package from somewhere other than PyPI?
Yes, but it is uncommon. You can install from a GitHub repository with pip install git+https://github.com/user/repo.git, or from a local file with pip install /path/to/package. Most packages you need are on PyPI, so start there.
What happens if two packages need different versions of the same dependency?
pip will try to find a version that works for both. If it cannot, you will see an error message. This is rare with well-maintained packages. If it happens, check the package documentation or use a virtual environment to isolate projects from each other.