10 ms·
Why to use ‘python -m pip’
- tofof 7y ago>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. 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.
- taeric 7y agoAgreed. Every time I see the story around version management in Python, I'm always at a loss to reconcile that to the "simpler" story of it.
- mehrdadn 7y agoWhat are some exemplary languages you have in mind that can substitute for Python?
- malvosenior 7y agoGolang is really good at a lot of the things Python is not (concurrency, package management, tooling, docs, types, good standard lib, easy to distribute...).
- awinder 7y agoGolangs package management is almost objectively a dumpster fire, confirmed by the fact that they’ve made at least 3 whacks at trying different esoteric things. There’s a lot of things that are nice about Go but package management is definitely not one of them.
- malvosenior 7y agoThis isn't true since `go mod` in Go 1.12. It's as good as Cargo and Lein now (both of which are also excellent). I'd recommend Rust and Clojure as well but Golang seems like a good next step for Python devs since it's the most similar.
- vonseel 7y agoRust package management is amazing but the language itself is not approachable at all in comparison to Python.
- takeda 7y agoStep backwards you mean. Go doesn't have package management, it's just list of git repositories and revisions that should be checked out and compiled with your code. In fact it is encouraged to have as little dependencies as possible.
- malvosenior 7y agoI fail to see how that's not package management.
- j88439h84 7y agoPython's story IMHO, - great concurrency (https://trio.readthedocs.io https://trio.readthedocs.io) - bad package management (it just is. though Poetry's making a dent.) - tooling? I'm not sure what you mean here. - docs are ok not great not terrible - types are rolling out rapidly across the ecosystem - stdlib is too big but PyPI is right there so who cares - ok to distribute? pyinstaller and shiv are alright.
- coldtea 7y ago>- tooling? I'm not sure what you mean here. He means linters, debuggers, refactoring libs, and other such things...
- lazzlazzlazz 7y agoGolang package management is monstrous.
- awinder 7y agoThis is certainly not one of the languages that the author is referring to, but I super appreciate how nodejs sandboxes modules with no fuss. Even within python virtualenvs I run into issues all the time where 2 modules have conflicting versions of a dependency and all hell breaks loose. The tradeoff is hard drive space but f-ing take it, that resource is the least constrained & the best fit to abuse in 2019.
- heavenlyblue 7y agoNah - what you simply need to do is to access the pip binary in the directory of the virtualenv (using PATH) you’re working with and simply stop using the system interpreter. That being said I would like to inquire which languages _you_ could give as an example that work perfectly well with the system-provided compilers when you are using the latest features.
- cfors 7y agoThe same issue occurs with Node and NPM. I don't want to speak for Ruby as I haven't used Ruby extensively but I can't imagine that Gem's and Ruby versions don't have the same issue. Honestly virtualenv's solve most of these problems. If using a virtualenv seem to low level or a pain, I can't recommend Poetry [0] enough. It uses virtualenv's in the background, and has from my experience a great dependency resolver. [0] https://poetry.eustace.io/ https://poetry.eustace.io/
- heavenlyblue 7y agoWhat about jvm, rust, scala, haskell? All of them require similar "cludges".
- EdwardDiego 7y agoHmm? Which cludges? Dependency management in JVM languages is painless compared to Python.
- brianwawok 7y agoWhat? How far back in time are you going? As far as I remember, it went Ant to Maven to Gradle? With some less popular offshoots like SBT and Ivy. All of those build tools are pretty complicated. I honestly prefer python and virtual environment. Simple requirements.txt file.
- EdwardDiego 7y ago
- swiley 7y agoJust switch to root from a ram disk and nuke it from orbit every few days! /s
- DataDaoDe 7y agoI solve this whole issue by using pyenv + direnv. I can have a project specific .python-version file and upgrade to a newer python version when necessary. Then I just run python -m venv env once on project creation and have direnv source env/bin/activate and can use pip as usual The articles arguments against this and for always using python -m pip don't convince me, personally. I never work on windows, so that's a mute point, and b/c I use direnv to automatically activate my env when cd'ing into the directory, I'm never not in the project environment. So basically, its impossible to not be using the correct pip version i.e. I have never once had this problem and I am constantly working on multiple python projects + code bases in various envs and versions.
- josteink 7y agoYou just do around twenty medium involved things manually because they’re not done for you by anyone else or any tool. And then python “just works”. Does your text editor know that? Your colleague? How about your CI-system? What about the deployment story? When are things “unexpectedly” going to break because not everyone knew all these informally applied requirements? Admit it: python is worst in class here. Almost no other popular language or platform forces it’s users into taking these absurd, error-prone steps, just to have basic shit “just working”. Take a look at Node: npm may be a mess for other reasons, but boooy do you have clean per project dependencies. Look at Cargo for something even better. Clojure has Lein. The new dotnet CLI is slick too. At this Python just plain sucks. It’s about time you guys start at least admitting it, or else it will never be fixed.
- DataDaoDe 7y agoYou can have your opinion, but to answer some of your questions, I use vscode and it works amazingly with python, so yes it does know what environment and python version you are using and can show source code, do type checking (if you use the "typing" module, and tons of other nice things that just work out of the box). As far as the CI-system knowing, there is not much difference in installing a particular version of rust/cargo say in a docker container and having a particular version of python installed in a container, so I don't really know what you are getting at. Could it be better? Sure, I do some programming in rust and IMHO the best build tool I've ever used is cargo. But compared to some of the other stuff you mentioned which I've used on projects as well (npm, lein specifically) I would say python is on the same level, and I prefer python over them but that's probably just my bad experience with package-lock/caching and long jvm load times speaking.
- empthought 7y agoAuthor's advice: type a dozen more characters. Your advice: forget whatever brought you to Python and start from scratch.
- Jsharm 7y agoPip is so bad vs rivals, conda is so much better I'm amazed it's not the recommended package manager.
- mehrdadn 7y agoWhat I don't get is why pip just happily uninstalls a package that breaks dependencies? It's like, "you had only 1 job..."
- Master_Odin 7y agoBecause it's not really a dependency manager, just a "dumb" installer and uninstaller. It's for this same reason you can specify an incompatible set of dependencies in requirements.txt and pip won't bat an eye.
- thecleaner 7y agoWhat about installing from source ? conda does not support it at all. For some esoteric python packages which use C++ or Cython backends, it is sometimes impossible to install those packages and installing from source becomes the only viable option. pip is quite awesome for this.
- j88439h84 7y agoPip 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. For installing global command-line scripts, I like pipx instead of pip. https://github.com/pipxproject/pipx https://github.com/pipxproject/pipx For development, I like Poetry instead of pip. https://poetry.eustace.io https://poetry.eustace.io
- pytester 7y agoThere's also pipsi.
- j88439h84 7y agoPipsi is unmaintained and replaced by pipx.
- keb_ 7y agoHaven't used Python in a long time, but last I remember, pipenv was the tool of choice. Frankly, I'm overwhelmed by all these choices. Does Poetry, pipsi, pipx, pipenv, and pip + venv all accomplish similar goals? Is it just a matter of preference?
- zem 7y agoif you use a per project venv I see no reason not to use `pip install`. if you don't use a per project venv, well, do that!
- hannibalhorn 7y agoYeah, venv's are a must. And to the article's "forgot to activate the venv" complaint, I highly recommend direnv. On top of activating the venv when (and only when) you're inside your project directory tree, you can use dotenv for loading all relevant env vars (AWS creds, API keys, etc.,) and add your project's root dir to PYTHONPATH with path_add.
- rmwaite 7y agoThe PIP_REQUIRE_VIRTUALENV environment variable also helps with this.
- yrro 7y agoThank you! Now if only this was documented! Come to think of it, only there was a PIP_DEFAULT_VIRTUALENV_PROJECTDIR variable which would causes pip to look upwards until it found a setup.py file, and then use a .venv directory in that directory by default...
- izietto 7y agoOr usev another version manager: I use asdf https://github.com/asdf-vm/asdf https://github.com/asdf-vm/asdf
- 0x8BADF00D 7y agoI 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.
- mehrdadn 7y agoI'm guessing you just never use Python 2? Otherwise it's hard to see how you don't run into issues.
- mixmastamyk 7y agoIt’s EOL in under two months.
- mehrdadn 7y agoIt's also Required By: apitrace apm asciidoc bluefish bzr cloudprint-cups dblatex epydoc fio gconf gemrb getmail gmock gnome-doc-utils gtk-recordmydesktop inkscape ipcheck ipython2 java-openjfx java11-openjfx java8-openjfx jcl jmc kig kodi-bin kodi-gbm kodi-wayland lhapdf lib32-apitrace libgda libkate libvirt-python2 libvolk lilypond mailman mcomix mediaproxy mercurial mftrace mod_wsgi2 moosefs mopidy mysql-python mysql-workbench nss-pam-ldapd ntop pluma pychecker pydb pylibacl pynac pypanel pyrex pyrit pysol-sound-server rdiff-backup repo rtaudio scribus sgmltools-lite shedskin singularity spambayes tellico texmacs tuxpaint txt2tags vim-ultisnips wesnoth wicd wifite xpra Optional For: android-tools arduino armagetronad boost boost1.69 brial bugzilla cairo-dock-plug-ins cantor cryptominisat5 csound dia ecasound ecryptfs-utils efl efl-docs faust freedroidrpg freeradius gammu geda-gaf gif2png git gogglesmm graphviz gvim hivex inn john kcachegrind-common kodi-eventclients kross-interpreters libdnet libevent libglade libieee1284 libnewt libproxy libuhd magma marsyas mate-menus mathomatic mediawiki munin-node ncmpc net-snmp non-timeline notmuch openconnect opensips plan9port postgresql pycharm-community-edition python-pywal recoll roundcubemail rrdtool singular skktools spectmorph spring subversion texlive-core texlive-music vim vim-latexsuite xf86-video-qxl Regardless, let's not turn this into yet another argument about why anyone should/shouldn't upgrade to Python 2. I was just trying to confirm that the parent is not doing anything that requires Python 2.
- mlthoughts2018 7y ago> “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?” 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. 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).
- bscphil 7y ago> 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. Exactly right. And on any sane Linux system the pip command should get you a version compatible with the system Python, which means this is a pointless extra step. Unless these instructions are supposed to be for Windows, or MacOS, in which case it should probably say so. (And doesn't everyone on Windows use Conda anyway?)
- pbreit 7y agoThis kind of stuff is my least favorite attribute of Python. Surely there must be a better way?
- WilliamEdward 7y agoOnce you figure out how venv works it's really simple to set up a python project. It's just another quirk with just another programming language, they all have them. People don't complain about how hard it is to learn to program, but learning how to use some pip commands is too difficult for them?
- m45t3r 7y agoSure it is a quirk, however it could really be better. Anyway, I think the fact that people has more patience with learning a language than tools is that learning a language is fun, while tooling is just boring.
- femto113 7y agoalias pip python -m pip then stop worrying about it
- luxuryballs 7y agojust don’t include that in a machine where the user doesn’t know it’s there until it’s the last thing they check to explain wtf is going on ;)
- kalenx 7y agoMaybe 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?
- bluedino 7y agoYou should be using a virtualenv
- diminoten 7y agoOkay, or just use pipenv. https://github.com/pypa/pipenv https://github.com/pypa/pipenv
- pm 7y agoYes, use pipenv or poetry. I don't know why there are still wars about this going on. Unfortunately there are people who complain that pipenv makes the ecosystem as bad as npm, which frankly is an improvement.
- brobinson 7y agoNot sure why this is downvoted. Only the uninformed are using (usually multiple, lol) requirements.txt files + raw `pip` and managing venvs themselves nowadays.
- diminoten 7y agoThere's a huge rift between hobbyist Python users and professional developers. That's okay, but the former group doesn't always like it when the latter group chimes in...
- at_a_remove 7y agoAs 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." Packaging is one of my least favorite things about the language I love the most.
- neurostimulant 7y agoCan you at least upgrade to latest version of python 2.7? If you're on at least python 2.7.9, pip should be already installed because it's included by default.
- jedberg 7y agoTo prevent accidentally installing in the global interpreter I have this in my .bash_profile: # pip should only run if there is a # virtualenv currently activated export PIP_REQUIRE_VIRTUALENV=true
- tus88 7y agoDo you type "sudo" by accident a lot?
- vonseel 7y agoPerhaps his global python doesn’t require sudo... it is pretty easy to install your own or change permissions of the default one, you know.
- coldtea 7y agoIf you do frequent admin work on a computer it's trivial to "type sudo by accident a lot", so I don't understand the spirit of the question...
- beagle3 7y agoJust 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. I really can't figure out why conda is not ore popular.
- robertk 7y agoHave you tried using it with larger projects? You can easily lose a day waiting for dependency resolution to finish — it takes forever.
- lsorber 7y agoIt's not fast on large environment.ymls, but recreating your environment isn't something you do daily so it's not that big of a deal for us.
- orf 7y agoAny project with CI should recreate the environment a lot. The lack of a Conda lockfile makes it impractical to use outside of toy research proof of concepts.
- beagle3 7y agoCI isn’t as sensitive to a few more seconds though, as it isn’t interactive. And while lockfiles are convenient, they are far from making anything “impractical”. I take Conrad correctness over minor conveniences any day.
- orf 7y agoIt adds many minutes on complex trees. That adds up fast if you’re doing just 60 builds a day. Lockfiles are not just convenient, they are all but required for anything serious. You can’t have your dependencies break or change under your feet from one build to the next. Your builds need to be reproducible. I’ll take all that over whatever conda has to offer any day.
- takeda 7y ago"that's why you should use virtualenv"
- IshKebab 7y agoTL;DR because Python is a mess, and installations are often messed up.
- m45t3r 7y agoPython itself is not a mess, the packaging part of Python is. However, Python is also one of the oldest programming languages still in use and one of the first to have the concept of installable dependencies (easy_install). Now it is kinda difficult to fix without breaking something, however I think we eventually will have a solution, like __pypackage__ https://www.python.org/dev/peps/pep-0582/ https://www.python.org/dev/peps/pep-0582/.