Difference in PIP format
Difference in PIP format
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'
pip
seems to be related
– Azat Ibrakov
Jul 3 at 8:33
3 Answers
3
With reference to this GitHub issue:
https://github.com/pypa/pip/issues/5373
Try the following command:
sudo easy_install pip
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>
This answer is not correct. If
pip is not in your PATH, you would get an error saying Command not found and not ModuleNotFoundError. So this is directly related with pip having been installed incorrectly or it breaking down.– BcK
Jul 3 at 8:33
pip
There is part of the answer which is correct. He asked about the difference between two types of commands too.
– Mufeed
Jul 3 at 8:45
I removed the part where I stated this may be the reason behind error.
– Mufeed
Jul 3 at 8:52
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).
pip
console_script
pip
In case of pip, the function they're executing using this method is set to pip._internal.main():
pip
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.
python -m pip
__main__.py
In case of python -m pip, this file essentially contains
python -m pip
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.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
It seems like pip is installed incorrectly, are you on linux, can you reinstall
pipplease ?– BcK
Jul 3 at 8:20