Reputation: 984
What is the difference between:
python -m pip install forecasting
and
pip install forecasting
In my environment, the first is working when the second format raise the following error:
ModuleNotFoundError: No module named 'pip._internal'
Upvotes: 1
Views: 197
Reputation: 36775
They're two different ways a package can expose commands to the commandline.
pip
is a console_script
entry-point. Any package can define globally available commands that way, and PIP (the package) uses it to define pip
(the command).
In case of pip
, the function they're executing using this method is set to pip._internal.main()
:
entry_points={
"console_scripts": [
"pip=pip._internal:main",
],
},
On the other side python -m pip
is using a switch for calling modules. If your module contains a __main__.py
file, this file will simply be interpreted and executed by the Python interpreter.
In case of python -m pip
, this file essentially contains
from pip._internal import main as _main
if __name__ == '__main__':
sys.exit(_main())
so the two commands try to do the same.
However, recently PIP has shown some weird quirks [1] [2] that cause one of the two to work, and the other one to fail.
Upvotes: 1
Reputation: 3208
Answer to your first question.
From pip docs
pip is a command line program. When you install pip, a pip command is added to your system, which can be run from the command prompt as follows:
$ pip <pip arguments>
If you cannot run the pip command directly (possibly because the location where it was installed isn't on your operating system's PATH) then you can run pip via the Python interpreter:
$ python -m pip <pip arguments>
Upvotes: 1
Reputation: 4460
With reference to this GitHub issue:
https://github.com/pypa/pip/issues/5373
Try the following command:
sudo easy_install pip
Upvotes: 1