» pip install pip
What's the difference between "pip install" and "python -m pip install"? - Stack Overflow
How can I Install a Python module with Pip programmatically (from my code)? - Stack Overflow
I think I have installed a dodgy pip package
pip is not safe
This was posted two days ago in this subreddit, and got 84 comments: http://www.reddit.com/r/Python/comments/17rfh7/warning_dont_use_pip_in_an_untrusted_network_a/
More on reddit.comVideos
I’ve been seeing pip/pip install and pypi everywhere but still unsure of what exactly it is. Anyone willing to explain in simple terms?
Factsheet
They do exactly the same thing, assuming pip is using the same version of Python as the python executable. The docs for distributing Python modules were just updated to suggest using python -m pip instead of the pip executable, because it allows you to be explicit about which version of Python to use. In systems with more than one version of Python installed, it's not always clear which one pip is linked to.
Here's some more concrete "proof" that both commands should do the same thing, beyond just trusting my word and the bug report I linked :)
If you take a look at the pip executable script, it's just doing this:
Copyfrom pkg_resources import load_entry_point
<snip>
load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
It's calling load_entry_point, which returns a function, and then executing that function. The entry point it's using is called 'console_scripts'. If you look at the entry_points.txt file for pip (/usr/lib/python2.7/dist-packages/pip-1.5.4.egg-info/entry_points.txt on my Ubuntu machine), you'll see this:
Copy[console_scripts]
pip = pip:main
pip2.7 = pip:main
pip2 = pip:main
So the entry point returned is the main function in the pip module.
When you run python -m pip, you're executing the __main__.py script inside the pip package. That looks like this:
Copyimport sys
from .runner import run
if __name__ == '__main__':
exit = run()
if exit:
sys.exit(exit)
And the runner.run function looks like this:
Copydef run():
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
## FIXME: this is kind of crude; if we could create a fake pip
## module, then exec into it and update pip.__path__ properly, we
## wouldn't have to update sys.path:
sys.path.insert(0, base)
import pip
return pip.main()
As you can see, it's just calling the pip.main function, too. So both commands end up calling the same main function in pip/__init__.py.
2021
This only happens if you create the venv with PyCharm. Please check if Scripts/pip-script.py located in your virtual environment
pip install and python -m pip install -- is not really the same. Or welcome back into the HELL of VERSIONING & DEPENDENCIES :-(
I was used to type pip(.exe) install <name> if I want install a package. But I run into trouble, if I try to install package Pillow. It breaks every time with an error message.
Today I retry python -m pip install copy&pasted from the manual and it works. Before I ignored it and type pip.... Because I thought it is the same.
I start to dive a little bit deeper into pip and I find this question/answer. After a while I found that pip.exe calls the script <virtual-environment/Scripts>pip-script.py.
I fighting with the installation of package Pillow.
Copy#! .\venv\Scripts\python.exe
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==19.0.3','console_scripts','pip3'
__requires__ = 'pip==19.0.3'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('pip==19.0.3', 'console_scripts', 'pip3')()
)
I was a little bit surprised that pip.exe still use the old version 19.0.3 of the package and not the new installed version 21.0.1.
I changed the two version strings by hand to 21.0.1. And now pip.exe was able to install Pillow proper.
From now I understand why pip still complains that I use an old version of pip.

I think the old v19 pip has problem to detect the supported platform and therefore sources instead of binaries are installed.
The officially recommended way to install packages from a script is by calling pip's command-line interface via a subprocess. Most other answers presented here are not supported by pip. Furthermore since pip 10.x, all code has been moved to pip._internal precisely in order to make it clear to users that programmatic use of pip is not supported.
Use sys.executable to ensure that you will call the same pip associated with the current runtime.
For example:
import subprocess
import sys
def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
[DEPRECATED since pip v10, March 2018 (see accepted answer instead)]
You can also use something like:
import pip
def install(package):
if hasattr(pip, 'main'):
pip.main(['install', package])
else:
pip._internal.main(['install', package])
# Example
if __name__ == '__main__':
install('argh')
» pip install all-packages
» pip install pandas


