How to Install Modules in Python?

Open a terminal or command prompt

Check that Python is installed with `python –version` or `python3 –version`

Check that pip is installed with `pip –version` or `pip3 –version`

Install a module with `pip install module_name`

Install a specific version with `pip install module_name==version_number`

Upgrade a module with `pip install –upgrade module_name`

Install multiple modules with `pip install module1 module2 module3`

Install from a requirements file with `pip install -r requirements.txt`

Use `python -m pip install module_name` if pip is not recognized

Use `python3 -m pip install module_name` on systems where Python 3 is separate

Activate a virtual environment before installing modules if using one

Create a virtual environment with `python -m venv venv`

Activate it on Windows with `venvScriptsactivate`

Activate it on macOS or Linux with `source venv/bin/activate`

Install modules inside the activated virtual environment with `pip install module_name`

Verify installation with `pip show module_name`

Verify in Python with `import module_name`

Suggested for You

Trending Today