Installing a Python module is pretty straightforward! Here’s how you can do it using pip
, which is the most common package manager for Python.
Step-by-Step:
- Open your terminal or command prompt:
- On Windows, open the Command Prompt or PowerShell.
- On Mac/Linux, open the Terminal.
- Use the pip command to install a module:
For example, if you want to install a module like
requests
, run the following command:pip install requests
Replace
requests
with the name of the module you’re installing. - Wait for the installation to finish: The terminal will download the module and install it, along with any dependencies.
- Verify the installation (optional): To ensure the module installed correctly, you can check by importing it in a Python script or interactive session:
import requests print(requests.__version__)
Additional Tips:
- For a specific version of a module:
pip install requests==2.25.1
- For installing modules in a virtual environment (recommended for managing dependencies for different projects):
- Create a virtual environment:
python -m venv myenv
- Activate it:
- On Windows:
myenv\Scripts\activate
- On Mac/Linux:
source myenv/bin/activate
- On Windows:
- Then, install your module as usual:
pip install requests
- Create a virtual environment: