#30367 closed Cleanup/optimization (fixed)
Docs: Change examples using bare `pip ...` to `python -m pip ...`
Reported by: | Ramiro Morales | Owned by: | Ramiro Morales |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Perhaps a minor detail in these times in which Django is Python3-only and usage of some form of virtualenv/minimal container is ubiquitous. But posting for consideration anyways just in case.
Using python -m pip install foo
makes sure the copy of pip
looked up and executed is the one installed for the interpreter copy currently in use (be it a system-wide or a virtualenv's)
This reduces the chances of failure (wrong pip
gets used and the install fails confusing the user or even worse the intended install action succeeds but against another copy of Python) in broken setups in which a leftover Python2 pip
or one associated with a different Python 3.x install is located in a directory which appears earlier in $PATH
.
Inspired by this article by Brett Cannon: https://snarky.ca/deconstructing-xkcd-com-1987/
Quoting:
Having
pip
installed is not a shocker. The real question is what interpreter pip is attached to? That's dependent on which Python interpreter was installed last in the earliest directory to have a Python interpreter in it. This is why you should always usepython -m pip
when executing pip to guarantee you are using pip with the interpreter you intend to install for.
Change History (7)
comment:1 by , 6 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 6 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 6 years ago
Patch needs improvement: | unset |
---|
comment:4 by , 6 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I think this makes sense. It's a bit more verbose, but removes a source of errors that are particularly hard to debug for beginners.