Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The real question is who runs python -m pip when there is a perfectly good /usr/bin/pip?


That's an easy question to answer.

python -m pip is often advised over pip or /usr/bin/pip, because it uses the version of pip associated with that particular major+minor python install.

https://snarky.ca/why-you-should-use-python-m-pip/


Wait, but isn't the point of the article that it will not do that, and rather just run the pip.py in you current working directory?


Only in the (probably unlikely) case that you have a `pip.py` in your CWD. In all other cases, it will execute pip as intended.


In the off chance that you have one, yes.

But in 99.9999999% of cases it will do what you expect (whereas "pip install x" will be easier to use the wrong one if you have multiple Python versions).


Even with the other form, if pip imports anything named like a pyhon module in the dl dir, it will be imported. That's because the current dir is automatically added to the PATH, using -m only add pip.py to the attack surface.


Guilty as charged. Using the system pip in an environment that doesn't use the system python is a recipe for disaster.


So is the common practice of running 'sudo pip install' which can create a world of pain.


I do it on Windows using the python executor py. So I'll run something like py -2 or py -3 or even py -3.8 to start the correct version of python when I'm not inside a venv.

Also the same goes for modules. Since I've installed youtube_dl in my global python 3 I'll always run it like py -3 -m youtube_dl and update it using py -3 -m pip install youtube-dl -U. Or to create a new python 2 venv (for whatever reason) py -2 -m virtualenv venv.


for a very long time (I don't use python as a daily driver, so not sure if it's still the case) guidance was to use `python -m pip` and if you tried to run `pip ...` it would explicitlytell you to run `python -m pip`. I regularly install python on clean systems and all of my scripts run `python -m pip`. Should I be changing?


You should always use this form if outside a virtualenv.


I do it all the time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: