How to install python modules and their dependencies easily?

The best and recommended way to install Python modules is to use pip, the Python package manager. It automatically installs dependencies of the module as well, making package management seamless and efficient.

Checking if pip is Already Installed

If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but should upgrade to the latest version.

On Linux or macOS

pip install -U pip setuptools

On Windows

python -m pip install -U pip setuptools

Installing pip on System-Managed Python

If you're using a Python install on Linux that's managed by the system package manager (e.g "yum", "apt-get" etc?), and you want to use the system package manager to install or upgrade pip, refer to the official Linux installation guide.

Manual pip Installation

If pip is not available, you can install it manually ?

  1. Download get-pip.py from bootstrap.pypa.io/get-pip.py
  2. Run python get-pip.py

This will install or upgrade pip on your system.

Installing Python Packages with pip

Installing the Latest Version

To install the latest version of a package ?

pip install requests

Installing a Specific Version

To install a specific version of a package ?

pip install requests==2.25.1

Installing Version Ranges

To install a version within a specific range ?

pip install 'requests>=2.20.0,<3.0.0'

Common pip Commands

Command Description
pip list Show installed packages
pip show package_name Show package information
pip uninstall package_name Remove a package
pip freeze Generate requirements file

Installing from Requirements File

To install multiple packages from a requirements.txt file ?

pip install -r requirements.txt

Conclusion

Pip is the standard tool for installing Python packages and their dependencies automatically. Always keep pip updated and use version specifications when needed for consistent deployments.

Updated on: 2026-03-24T17:09:41+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements