1. Use something that manages virtualenvs + packages for you.
2. Don’t use something that manages virtualenvs + packages for you.
For 1 you have poetry or pipenv. For 2 you have… well virtualenv/pip. It’s really not that complex and I don’t get where this sentiment comes from.
You’ve already listed four separate applications: poetry, pipenv, virtualenv and pip. And if you look online you’ll also find Anaconda and probably several others. For a Python beginner, it’s confusing to try figure out the exact differences between them — let alone what exactly a ‘virtualenv’ is or why you would want to use it.
By comparison, Haskell — a language with a reputation for poor dependency management — has only two competing package managers, and these are practically identical. Most other languages have only one ‘official’ package manager. No wonder people find Python dependency management confusing!
So that’s the base level. You’ve got pip and virtualenv. Everything else builds ontop of that.
But hey it turns out it would be cool to iterate on stuff outside of Python itself. And maybe there are some useful things we can add to pip and virtualenv? And so Poetry and Pipenv are born.
It’s probably Stockholm syndrome but this seems pretty simple.
There are multiple PEPs about pip.
https://www.python.org/dev/peps/pep-0453/ makes it as official as it gets.
Source: I am a pip maintainer and a PyPA member.
Oh damn, well consider me schooled. Fair enough!
- pipx
- nix-shell (my current solution)
Pyenv: tool to manage different python major/minor/patch versions.
Pipx: installs CLI/GUI tools in their own virtualenv and links them to ~/.local/bin. Way more convenient if you have commonly used tools
virtualenv: use to isolate python environments
Pip: used to install packages
Conda: basically does all the above, also handles linked libraries and a bunch of stuff. Annoying for deployment, but it's often the least worst option.
Python-N.M: use pyenv to manage your python installations. Way cleaner than brew. Never use system python for things.
Python2 thru 3.3: you really ought to be using py>3.6 by now, but it may not be your choice. I haven't in years but I think you can use pipx or "pip install --user virtualenv" to get the virtualenv binary. Then use virtualenv from there.
Py>3.3: use "python -m venv" to manage virtualenvs. Use pipx to install cli tools. Do everything in venvs.
On windows or if you rely on lots of academic packages: you are probably better off just using conda.
Also the pre-commit tool manages its own virtualenv cache, which is cool for making repos easy to bootstrap.
There's also poetry, but it's more new and if you are at the point in your python journey that you are asking these questions, then in my opinion it's likely to just muddy the waters more.
And if anyone is curious "why the hell is python this way? I don't have this problem with $LANGUAGE?" It's because when python fires up, basically a small miracle occurs that is able to locate and execute .py, .pyc, .zip, several other file types, directories, compiled libraries, and basically anything you want if you override the module machinery.
That being said, I’ve been using Python for 16 years now and for me poetry is pretty close to nirvana. Not perfect, but really good. Handles virtualenv management, locking, dependency specification, etc etc.
Uhh, I’m struggling to think of anything else. It makes requirements.txt based projects feel barbaric and that will make you feel bad working with them?
pip3 and virtualenv.
Both are pretty easy to learn. Everything else is pretty much an abstraction layer on top of one or both of the above.
This feels a bit anti-intellectual to me. Like any other thing, it takes a bit of reading to figure our virtual environments, but its literally one line to create a new one one you know how (I almost always use Conda). I don't see how this is different than the setup used for any development, and I can't imagine it's a major impediment, certainly not a lasting one, to people working in python. You could always open a colab notebook if you really don't want to be bothered.
The problem is that depending on what article you read or what tutorial you follow you'll learn different things.
I recently wanted to write something using flask. I followed 4 different tutorials and all 4 did things differently (and none of them mentioned Conda or Poetry). I had a similar experience writing a Telegram bot.