poonam
2 min readJun 6, 2023

“pip install” and “python -m pip install” difference.

Both pip install and python -m pip install are commands used to install Python packages using pip, the package installer for Python.

The main difference between the two commands lies in how they are executed:

  1. pip install: This is the more common and straightforward way to install packages using pip. It is executed directly from the command line or terminal by typing pip install <package_name>. For example, to install the requests package, you would run pip install requests. This command assumes that pip is already in your system's PATH, allowing you to execute it directly.
  2. python -m pip install: This alternative command explicitly runs pip as a module within the Python interpreter*. It is executed from the command line or terminal by typing python -m pip install <package_name>. Using this command ensures that you are using the pip associated with the Python interpreter you're currently using. This can be useful in cases where you have multiple Python installations or virtual environments. It helps avoid potential conflicts and ensures that the package is installed in the correct environment.
  • Within the Python interpreter :

when you use it, you are invoking the the module as a script within the Python interpreter.

The python -m the command allows you to run a Python module as a script from the command line. In this case, you are running the pip module as a script by specifying pip after the -m option. The install command is then passed as an argument to the pip module, indicating that you want to install a package.

By using python -m pip install, you ensure that the correct version of pip associated with the Python interpreter you're using is used for the installation. It helps avoid potential conflicts when multiple Python installations or virtual environments are present.

In summary, python -m pip install explicitly runs the pip module within the Python interpreter and is particularly useful when you want to ensure that the package is installed in the context of the specific Python environment you're currently using.

In most cases, you can use either command to install Python packages, and the result will be the same. However, if you’re working with multiple Python installations or virtual environments, using python -m pip install can provide more control and ensure that the package is installed in the desired environment.

Also, for the difference between the python setup.py install and pip install, check out the link.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

poonam
poonam

Written by poonam

An Engineer and philosopher

No responses yet

Write a response