TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why to use ‘python -m pip’

135 pointsby pyprismover 5 years ago

15 comments

jedbergover 5 years ago
To prevent accidentally installing in the global interpreter I have this in my .bash_profile:<p><pre><code> # pip should only run if there is a # virtualenv currently activated export PIP_REQUIRE_VIRTUALENV=true</code></pre>
评论 #21431700 未加载
tofofover 5 years ago
&gt;Now you may be saying, &quot;I always install the latest versions, so that would mean Python 3.8.0 was installed last since it&#x27;s newer than 3.7.5&quot;. OK, but what happens when Python 3.7.6 comes out? Your pip command would have gone from using Python 3.8 to Python 3.7.<p>This seems less like a reason to use `python -m pip` and more a reason to endorse languages with saner versioning and less need to sandbox twenty different versions from one another.
评论 #21430285 未加载
评论 #21430843 未加载
评论 #21430442 未加载
评论 #21430254 未加载
评论 #21430171 未加载
评论 #21430410 未加载
beagle3over 5 years ago
Just use [mini]conda. Everytime someone posts about a python package issue or virtual env issue, it&#x27;s something that conda already had solved before 2014. And yes, pip is fully supported within a conda environment.<p>I really can&#x27;t figure out why conda is not ore popular.
评论 #21432156 未加载
j88439h84over 5 years ago
Pip is a powerful but low-level tool, which probably shouldn&#x27;t be user-facing. It doesn&#x27;t have a full resolver, locking mechanism, or environment management. Likewise setuptools.<p>For installing global command-line scripts, I like pipx instead of pip. <a href="https:&#x2F;&#x2F;github.com&#x2F;pipxproject&#x2F;pipx" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pipxproject&#x2F;pipx</a><p>For development, I like Poetry instead of pip. <a href="https:&#x2F;&#x2F;poetry.eustace.io" rel="nofollow">https:&#x2F;&#x2F;poetry.eustace.io</a>
评论 #21430848 未加载
评论 #21430610 未加载
mlthoughts2018over 5 years ago
&gt; “Let&#x27;s say I have two versions of Python installed, like Python 3.7 and 3.8 (and this is very common for people thanks to Python coming installed on macOS and Linux, let alone you may have installed Python 3.8 to play with it while having previously installed Python 3.7). Now, if you were to type pip in your terminal, which Python interpreter would it install for?”<p>Yeah but you just kick the can to which python happens to be the system python or activated python referenced by “python”. It’s exactly the same problem.<p>If I as a user have to be careful of which underlying Python installation is being referenced, then I want to be responsible for activating the conda environment I need and using “regular” commands like plain “pip” after that. The “python -m” idiom is not important for this use case, as it doesn’t actually solve the problem (ensuring the right referenced Python).
评论 #21431486 未加载
zemover 5 years ago
if you use a per project venv I see no reason not to use `pip install`. if you don&#x27;t use a per project venv, well, do that!
评论 #21430234 未加载
kalenxover 5 years ago
Maybe it&#x27;s just on my installation, but pip comes with versioned executables. That is, I can call &quot;pip3.7&quot; or &quot;pip3.4&quot;. What&#x27;s the benefits of using the -m approach in this case?
评论 #21431005 未加载
Jsharmover 5 years ago
Pip is so bad vs rivals, conda is so much better I&#x27;m amazed it&#x27;s not the recommended package manager.
评论 #21430292 未加载
评论 #21430131 未加载
评论 #21430105 未加载
评论 #21430682 未加载
femto113over 5 years ago
<p><pre><code> alias pip python -m pip </code></pre> then stop worrying about it
评论 #21430879 未加载
at_a_removeover 5 years ago
As someone who is stuck on a very old version of python (2.7) on win32 due to Reasons (vendors, basically), how I wish I could even try to install pip; unfortunately, it will only recommend upgrading to a newer version of python when I attempt. All roads seem to lead to this place, a one-size-fits-all dismissive &quot;lol upgrade.&quot;<p>Packaging is one of my least favorite things about the language I love the most.
评论 #21432460 未加载
pbreitover 5 years ago
This kind of stuff is my least favorite attribute of Python. Surely there must be a better way?
评论 #21430743 未加载
takedaover 5 years ago
&quot;that&#x27;s why you should use virtualenv&quot;
IshKebabover 5 years ago
TL;DR because Python is a mess, and installations are often messed up.
评论 #21433631 未加载
diminotenover 5 years ago
Okay, or just use pipenv.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;pypa&#x2F;pipenv" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pypa&#x2F;pipenv</a>
评论 #21431020 未加载
评论 #21431715 未加载
0x8BADF00Dover 5 years ago
I usually use pip3 install --user. Then just add ~&#x2F;.local&#x2F;bin to PATH. It hasn&#x27;t caused any issues for me thus far. I also use venv, but only in CI to make sure that other people&#x27;s environments don&#x27;t get messed up. I personally prefer using pip3 install --user.
评论 #21430615 未加载
评论 #21430237 未加载