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>
>Now you may be saying, "I always install the latest versions, so that would mean Python 3.8.0 was installed last since it's newer than 3.7.5". 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.
Just use [mini]conda. Everytime someone posts about a python package issue or virtual env issue, it's something that conda already had solved before 2014. And yes, pip is fully supported within a conda environment.<p>I really can't figure out why conda is not ore popular.
Pip is a powerful but low-level tool, which probably shouldn't be user-facing. It doesn'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://github.com/pipxproject/pipx" rel="nofollow">https://github.com/pipxproject/pipx</a><p>For development, I like Poetry instead of pip. <a href="https://poetry.eustace.io" rel="nofollow">https://poetry.eustace.io</a>
> “Let'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).
Maybe it's just on my installation, but pip comes with versioned executables. That is, I can call "pip3.7" or "pip3.4". What's the benefits of using the -m approach in this case?
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 "lol upgrade."<p>Packaging is one of my least favorite things about the language I love the most.
Okay, or just use pipenv.<p><a href="https://github.com/pypa/pipenv" rel="nofollow">https://github.com/pypa/pipenv</a>
I usually use pip3 install --user. Then just add ~/.local/bin to PATH. It hasn't caused any issues for me thus far. I also use venv, but only in CI to make sure that other people's environments don't get messed up. I personally prefer using pip3 install --user.