Use 'python -m pip' Everywhere2020-02-25
I’ve just moved all my open source repositories from using plain
python -m pip, in test scripts and documentation.
This is following Brett Cannon’s article from November last year Why you should use
python -m pip, and Donald Stufft’s 4.5 year old issue on the Pip repo itself.
Both describe in depth the problems that using the
pip executable can lead to, and are well worth a read.
In brief, the main problem:
Most Python developers install more than one Python version. This is either due to their OS including an old Python by default, working on projects that use different versions, or simple experimentation.
pip executable with more than one Python version can be unpredictable.
When you upgrade pip on one version, it can replace the executable from the other.
pip install at one moment might use Python 2.7, then later it could use Python 3.7.
It’s not hard to see how this can lead to problems understanding what’s installed where and when.
When you use
python -m pip, the pip package is executed explicitly with the version of Python that
python points to.
If you have other interpreters, you can use them precisely and predictably, e.g.
python3.6 -m pip.
More typing, but much less trouble.
python -m pip,
python -m pip was actually my entry in the “Is there a Dr. on this flight?” Twitter meme.
Interested in Django or Python training? I'm taking bookings for workshops.
One summary email a week, no spam, I pinky promise.
- Why does Python 3.8 log a SyntaxWarning for 'is' with literals?
- Feature Checking versus Version Checking
- Limit Your Try Clauses in Python
© 2020 All rights reserved.