The fastest way to install a Python module is with pip, Python's built-in package manager
Open your terminal or command prompt and type pip install module_name, replacing module_name with the actual name of what you want. For example, to install the requests library (used for downloading web pages), you would type pip install requests. pip downloads the module from PyPI (Python Package Index) and puts it where Python can find it.
That one command is usually all you need. pip handles finding the right version, downloading dependencies the module needs, and placing files in the correct folders. You do not have to manually download anything or move files around.
The catch: if you have multiple Python projects on your machine, installing modules globally (the default) can create conflicts. One project might need version 2.0 of a library while another needs version 3.0. Virtual environments solve this by giving each project its own isolated set of modules.
Key Takeaways
- The command pip install module_name downloads and installs a module from PyPI in seconds, and is the standard way most Python users add code to their projects.
- Virtual environments let you install different versions of the same module for different projects without conflicts, and are worth setting up even for small scripts.
- On Windows, you may need to use python -m pip install instead of pip install if pip is not recognized as a command.
- You can install multiple modules at once with pip install module1 module2 module3, or from a list saved in a requirements.txt file.
Check that pip is installed and working
Before you install anything, verify that pip exists on your machine. Open your terminal (on Mac or Linux) or Command Prompt (on Windows) and type pip --version. You should see a version number like "pip 23.1.2 from /usr/local/lib/python3.11/site-packages/pip". If you see "command not found" or "pip is not recognized", pip is not in your system path.
If pip is missing, the most reliable fix is to use Python's built-in module runner instead. Type python -m pip install module_name (or python3 -m pip install module_name on Mac). This tells Python to run pip as a module, which works even if pip is not in your path. On Windows, you may need to use this syntax by default.
To confirm Python itself is installed, type python --version or python3 --version. You need Python 3.4 or later for pip to work properly.
Create a virtual environment for your project
A virtual environment is a folder on your computer that holds a copy of Python and its own set of installed modules, separate from your system Python. When you activate a virtual environment, pip installs modules into that folder instead of globally.
To create one, navigate to your project folder in the terminal and type python -m venv venv. This creates a folder called venv (you can name it something else, but venv is the standard). The command takes a few seconds and creates several subfolders inside.
Next, activate the virtual environment. On Mac or Linux, type source venv/bin/activate. On Windows, type venv\Scripts\activate. Your terminal prompt will change — you will see (venv) at the start of the line. This tells you the virtual environment is active and pip will install modules into it, not globally.
When you are done working on the project, type deactivate to exit the virtual environment. The (venv) prefix disappears from your prompt.
Install a single module with pip
With your virtual environment active (or if you are installing globally), type pip install requests to install the requests module. Replace requests with whatever module you need. pip downloads the module and any other modules it depends on, then installs them all.
The output will show what was downloaded and where it was placed. You will see lines like "Successfully installed requests-2.31.0" at the end. If the module is already installed, pip tells you so and does nothing.
To install a specific version of a module, use pip install requests==2.28.0 (double equals sign). This is useful when you know a newer version breaks your code. To install the latest version of a module you already have, type pip install --upgrade requests.
Install multiple modules at once
You can install several modules in one command by listing them with spaces: pip install requests beautifulsoup4 flask. pip downloads and installs all three.
For projects with many dependencies, create a file called requirements.txt in your project folder. List each module on its own line, with optional version numbers:
requests==2.31.0 beautifulsoup4==4.12.0 flask>=2.0.0
Then type pip install -r requirements.txt. pip reads the file and installs everything listed. This is the standard way teams share projects — you commit requirements.txt to version control, and anyone who clones the project can recreate the exact same environment with one command.
Troubleshoot common installation problems
If you see "No module named pip", use python -m pip install module_name instead. If you see "Permission denied" on Mac or Linux, do not use sudo — it installs modules outside your virtual environment and can break things. Instead, make sure your virtual environment is active (you should see (venv) in your prompt).
If pip says "Could not find a version that satisfies the requirement", the module name may be spelled wrong or may not exist on PyPI. Search PyPI.org to confirm the exact name. Some modules have hyphens in their PyPI name but underscores in the import statement, or vice versa — the PyPI page shows both.
If you get "ERROR: Could not install packages due to an EnvironmentError", your disk may be full or you may not have write permission to the folder. On Windows, try running Command Prompt as Administrator. On Mac or Linux, check that your virtual environment folder is writable.
Verify that a module installed correctly
After installation, you can test that the module works by opening a Python interpreter and importing it. Type python to start the interpreter (you should see >>> at the prompt). Then type import requests (or whatever module you installed). If nothing happens, the import succeeded. If you see "ModuleNotFoundError", the module did not install correctly.
You can also list all installed modules by typing pip list in your terminal. This shows every module pip knows about in your current environment, along with version numbers. Scroll through the list to confirm your module is there.
To see where a module is installed, type pip show requests. This displays the module's location, version, dependencies, and other metadata. Useful for debugging when you have multiple Python installations.
Frequently Asked Questions
Do I have to use a virtual environment?
No, but you should. Virtual environments prevent version conflicts and make it easy to share your project with others. Even for small scripts, they take 30 seconds to set up and save you hours of debugging later. If you are just learning Python, start with a virtual environment from the beginning.
What is the difference between pip and conda?
pip is Python's standard package manager and works with modules on PyPI. conda is a separate tool that comes with Anaconda (a Python distribution) and can install non-Python software too. For most projects, pip is what you need. conda is more common in data science and scientific computing.
Can I install a module from a file instead of PyPI?
Yes. Type pip install /path/to/module.whl or pip install /path/to/module.tar.gz to install from a file on your computer. You can also install directly from a GitHub repository with pip install git+https://github.com/user/repo.git.
What happens if I install a module without a virtual environment?
It installs globally, meaning all your Python projects can use it. This works fine for small scripts, but causes problems when different projects need different versions of the same module. You will eventually hit a conflict that forces you to choose which project gets the version it needs.
How do I uninstall a module?
Type pip uninstall module_name. pip asks for confirmation, then removes the module. To uninstall everything in a requirements.txt file, type pip uninstall -r requirements.txt -y (the -y skips the confirmation prompt).