How to Install Python Module using Pip

To install a Python module using pip, you can use the “python3 -m pip install packagename” or “pip install packagename” command in your terminal. The command will install the latest version of the module and its dependencies from the Python Packaging Index.

python -m pip install packagename

I am using Python3, so I can use the following command to install Python modules.

python3 -m pip install packagename

For Windows users, the examples in this tutorial assume that the option to adjust the system PATH environment variable was selected while installing Python.

Install specific Python 3 module versions

You can specify the exact or minimum version directly on the command line.

The package name and version should be enclosed within double quotes when using the comparison operators such as >, <, or some other special character that the shell interprets.

python -m pip install packagename==1.0.4 # specific version
python -m pip install "packagename>=1.0.4" # minimum version

# For Python3
python3 -m pip install packagename==1.0.4 # specific version
python3 -m pip install "packagename>=1.0.4" # minimum version

If a suitable module is installed, attempting to install it again will not affect it.

I have already installed pip on my system, but let’s try to install it again and see what we are getting in the command line.

python3 -m ensurepip --default-pip


python3 -m ensurepip --default-pip
Looking in links: /var/folders/7m/122nrwsx5451db3nvfh157zh0000gn/T/tmpthkp5ef7
Requirement already satisfied: setuptools in ...
Requirement already satisfied: pip in ...

You can see that we are getting messages like Requirement already satisfied.

Upgrading existing modules must be requested explicitly

We can explicitly request that we have to upgrade any particular module. You can check out a tutorial on upgrading pip in Python in this blog.

To upgrade any package in Python, you can use the following syntax.

python3 -m pip install --upgrade packagename

How to work with multiple versions of Python installed in parallel?

On Linux, macOSX, and other POSIX systems, use the versioned Python commands combined with a -m switch to run the appropriate copy of pip.

python2 -m pip install packagename # default Python 2
python2.7 -m pip install packagename # specifically Python 2.7
python3 -m pip install packagename # default Python 3
python3.4 -m pip install packagename # specifically Python 3.4
python3.8 -m pip install packagename # specifically Python 3.8

In the first section of this article, we have used default Python3 because right now, only one Python 3.x is installed on my machine, which is Python 3.8.

Appropriately versioned pip commands may also be available.

On Windows, use a py Python launcher with a –m switch.

py -2 -m pip install packagename # default Python 2
py -2.7 -m pip install packagename # specifically Python 2.7
py -3 -m pip install packagename # default Python 3
py -3.4 -m pip install packagename # specifically Python 3.4
py -3.8 -m pip install packagename # specifically Python 3.8

Different ways to install and manage Python modules

Python pip

Pip is a preferred installer program. Starting with Python 3.4 is included out of the box with the Python binary installers.

The virtual environment is a semi-isolated Python environment that allows packages to be installed by the specific application rather than being installed system-wide.


Python venv is a standard tool for creating virtual environments in your system and has been part of Python since Python 3.3.

Starting with Python 3.4, it defaults to installing pip into all the created virtual environments.


Python virtualenv is a third-party alternative (and predecessor) to venv. The virtualenv allows virtual environments to be used on the versions of Python before 3.4, which either don’t provide venv at all or aren’t able to install pip into created environments automatically.

Install Packages and Modules using a pip

If you don’t know what your installed pip’s version is, you can fire the following command to check the version of pip.

pip --version
pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)

Now that you have pip, it is easy to install Python modules since it does all the work for you. When you find the module you want to use, the documentation or installation instructions usually include the necessary pip command, such as the following.

See the syntax of the pip command.

pip install package_name

Install some Python modules using pip.

pip install requests
pip install beautifulsoup4

For Mac and Linux, you might need to run pip with sudo, like the following.

sudo pip install requests

Uninstall a Package using PIP in Python

To uninstall a package using pip, type the following command in the command line or terminal.

pip uninstall packagename

In our example, let’s can uninstall the beautifulsoup4 package.

pip uninstall beautifulsoup4

That’s it.

1 thought on “How to Install Python Module using Pip”

  1. Nice post.
    I personally prefer using pipenv. It’s a little more helpful. For instance it tells you which package got installed as a result of it being a dependency of another package.

    So when you want to uninstall a package. pip would only uninstall that package.. Using pipenv you can get rid of the extra packages that were installed (cyclical dependencies) as well.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.