Virtual Environments Demystified
meribold.org
meribold.org
1. You have to manually freeze packages (instead of automatic package-lock.json)
2. Each time your install/remove package, dependant packages are not removed from freeze. You have to do it manually. (interesting link: https://github.com/jazzband/pip-tools)
3. Freeze is flat list (npm can restore tree structure)
Poetry is what's most comparable and personally, i am not working in python projects that don't use poetry anymore. Whenever I work on a new one, i port it to use poetry
If your new to poetry and pyenv I can't recommend https://cjolowicz.github.io/posts/hypermodern-python-01-setu... enough. Even with 10 years python experience it changed how I work with it for the better.
It's something every python developer should read because if you're not using poetry for example, then you're making your development life more difficult than necessary.
Again I am not sure if that is why Python can't support a tree or simply why it doesn't currently support a tree, I searched for a PEP explicitly defining dependency resolution but couldn't find one.
I don't work on any significant python code bases, so I expect it has limitations when compared to the virtual env options like developing with specific (or multiple) python versions.
distutils.errors.DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base
I don't understand why this doesn't work, but it seems like it should.I was able to install those 2 packages in a virtualenv (although weirdly Dreamhost requires you to build your own Python 3 to do that, python3 -m venv doesn't work)
I've been programming Python since 2003 and have no idea what's wrong :-(
TBH I thought I was a luddite for avoiding virtualenv and pip for a long time. I would downloads tarballs and use distutils to build them! But for this project I'm using flask which has more dependencies... Gah. And now I'm seeing all the downsides...
I learn best how something works if I try to re-create it. But there is not enough time to do it for all the things around. Explanations like this kind of simulate that process for me.
- pyenv is used to manage which Python versions you have installed
- venv comes with Python and is used to actually create virtualenvs
- `poetry install` will create a virtualenv for you, install your packages into it, and create a lock file (assuming your project is configured to use poetry)
- tox is used to run your test suite against multiple Python versions (but you don't use it to directly manage virtualenvs)
Tox is another great tool, but imho only if your project has a strict requirement for multiple python versions. Otherwise, it's a waste of effort.
I found it interesting because I am generally in the distro-package camp vs venvs, and I do not see any other point myself. And for conflicting dependencies, I strive to solve that with barebone VMs to run individual "services" (or containers if security is not a concern).
What's stopping the wider community to finally adopt any sort of namespacing / switches / gemsets / per-project environments? And I mean automatic; you `cd` into the directory and it's handled for you, similar to the the functionality of the `direnv` and `asdf` generic tools, and Elixir mix's / Rust cargo's / Ruby RVM's ways of isolating apps and their dependencies.
Why is Python lagging behind so many other ecosystems? Why is it so persistent in not fixing this? It's obvious it's not going anywhere and a lot of people are using it. Why not invest in making it as ergonomic as possible?
And don't give me the "backwards compatibility" thing now. Everyone I know that uses Python also uses several such tools on top of the vanilla experience -- so I'd argue the vanilla experience is mostly a theoretical construct for years now and can be almost safely assumed to not exist.
(And I get sadder engaging with HN these days. If you don't think I am right, engage in an argument. This downvote-and-navigate-away practice that's been creeping up from Reddit to HN isn't making this place any favours and it starts to remove the community aspect for me with time.)
Who knows, same with the GIL, they want to wait for a community solution I guess.
Neither the practice of downvoting on HN nor the rules around it have changed in many years. If you're noticing it more, there must be some other reason for that.