Live data from Hacker News

Python environment setup seems complicated and unsolvable

stackoverflow.com

11–20 of 34 posts

Re: Python environment setup seems complicated and unsolvable

#11

> Instead of creating virtual environments using venv, you can use a more sophisticated tool like Poetry which enables you to manage you environments in a much better manner. It seems pretty emblematic of the shitshow that is Python environment management that the top-rated comment is recommending something I've never heard of. I know pyenv and pyvenv (not the same thing!) and virtualenv and venv (not the same thing!…

Yes, but unironically

Re: Python environment setup seems complicated and unsolvable

#12
I use Nix to manage python environments, and it’s quite revealing.

For instance, a few months ago I was working on an environment for playing around with some libraries that you’d think would commonly go together. But within the community there are very popular libraries that cannot be used together (at recent enough commits to contain features I want) due to version conflicts.

But as I’m a nix person I obviously try to solve that by going rogue. This was my process before I decided to pack it in and wait for the community to sort their shit out:

1. Pull projects at their latest commit instead. This is the “hope the communities already have their shit sorted out” method. nope, no luck.

2. Write a patch that changes the older requirement. Maybe it is API compatible? LOL no such luck.

3. Write a patch that changes the outdated dependency name to some random name, then add an expression to map the outdated dependency to that name instead. Ugh no, there are version incompatibility with its own dependencies too.

4. Write a patch to update the lib with the outdated dependency to use the new API instead - success! On its own. Now use it together with the other libraries… uh oh.

It has a C++ backend that requires a GLIBC version that is incompatible with that used by the other libraries. It needs this because it needs to be built with a specific CUDA-enabled compiler that is quite outdated now, and if you compile it on a newer version it fails to build because the author hardcoded the compatibility matrix into the codebase with c macros.

So yeah there comes a point where you think “hey I want to try out using some fun tools I’ve heard about” and, before you know it, you’re writing a patch for a dependency that allows you to use a patched version of another dependency that allows you to use a patched version of a dependency that you want to add to your project alongside something else, and at some point you’ve just got to quit and hope that in a few weeks there will be version parity.

Re: Python environment setup seems complicated and unsolvable

#13

I just gave up on learning Python because of this mess. It's really too bad, because I'd like to write utilities with Python that would run on almost any machine. Oh well. When I was still trying to wrangle this, I had followed this guide on setting up Python "the right way." I wonder what y'all think: https://opensource.com/article/19/5/python-3-default-mac

Looks mostly good, but also has extra elements you don’t really need.

Pyenv - managing / installing multiple python versions.

Then all you need to start is regular virtual environments ‘python -m venv .venv’ with ‘requirements.txt’, but I also recommend poetry. This is for dependency isolation between projects.

Packaging up projects for distribution is a whole other venture though!

Re: Python environment setup seems complicated and unsolvable

#14
post #10

IMHO, Poetry is the best we have in the Python dep mgmt space, and it's still endlessly frustrating. It's especially hard to recommend it for newbies looking to get up and running with even a simple ML stack. Check out this thread[1] on the Kafkaesque nightmare that is trying to install PyTorch with Poetry. [1]: https://github.com/python-poetry/poetry/issues/6409

Poetry won’t ever be the answer because the Poetry maintainers haven’t shown the maturity to be real leaders in the space. It’s good, as many narrowly opinionated projects are, but ultimately the core maintainers are not interested in use cases they see as outside their vision for the tool. Which means it will never be the one tool to rule them all.

Re: Python environment setup seems complicated and unsolvable

#15

> Instead of creating virtual environments using venv, you can use a more sophisticated tool like Poetry which enables you to manage you environments in a much better manner. It seems pretty emblematic of the shitshow that is Python environment management that the top-rated comment is recommending something I've never heard of. I know pyenv and pyvenv (not the same thing!) and virtualenv and venv (not the same thing!…

Funnily enough, Poetry only just very recently started to properly support PyTorch (you know, which seemingly 90% of Python usecases nowadays require). Like, it would not work across different setups with Arm, Cpu and Gpu machines, which is the point of poetry.

For years, youd need to use one of a few hacks that had serious downsides. Our deployments still install pytorch stuff separately in every container.

I think this is still one of the top (open) issues on the repo.

Also, for sufficiently sophisticated projects, poetry was known to lead to hour long dependency resolving sessions. For example, if you feel like using different pypy sources (eg internal registry, plus some wheels etc), poetry will try to install every package from every of these source registry meaning creating a lock file takes now hours. Not sure if this was ever resolved, but at my company, poetry is know as the thing that never works.

Re: Python environment setup seems complicated and unsolvable

#16
post #10

IMHO, Poetry is the best we have in the Python dep mgmt space, and it's still endlessly frustrating. It's especially hard to recommend it for newbies looking to get up and running with even a simple ML stack. Check out this thread[1] on the Kafkaesque nightmare that is trying to install PyTorch with Poetry. [1]: https://github.com/python-poetry/poetry/issues/6409

For ML projects, conda is still better since it usually manages to resolve a working environment including pytorch and cuda.

Sure, it doesn’t lead to the same exact environment on every machine, but that stuff never ever works anyway at least with portry.

Re: Python environment setup seems complicated and unsolvable

#17

I use Nix to manage python environments, and it’s quite revealing. For instance, a few months ago I was working on an environment for playing around with some libraries that you’d think would commonly go together. But within the community there are very popular libraries that cannot be used together (at recent enough commits to contain features I want) due to version conflicts. But as I’m a nix person I obviously try…

Part of the problem is that nix takes an opposite stance from where python seems to be heading…

Poetry, pipenv, etc are all about building dependency tree solvers into python package management.. so if you have package a that depends on package c >= 2.0 and package b that depends on package c Nix basically says “Python packages are lying when they say they need this specific package version. Ignore that and install whatever version is in nixpkgs”.

Which sucks! There are some badly maintained workarounds (poetry2nix and pip2nix come to mind… neither of which works for m1 macs), but the whole stance is just wrong.

Re: Python environment setup seems complicated and unsolvable

#18
post #17

I use Nix to manage python environments, and it’s quite revealing. For instance, a few months ago I was working on an environment for playing around with some libraries that you’d think would commonly go together. But within the community there are very popular libraries that cannot be used together (at recent enough commits to contain features I want) due to version conflicts. But as I’m a nix person I obviously try…

Part of the problem is that nix takes an opposite stance from where python seems to be heading… Poetry, pipenv, etc are all about building dependency tree solvers into python package management.. so if you have package a that depends on package c >= 2.0 and package b that depends on package c Nix basically says “Python packages are lying when they say they need this specific package version. Ignore that and install w…

I believe, having recently installed Python libraries on it, that Debian stable has the best handle on what to do to produce defaults that a mere mortal can debug: Either use what's vendored in apt, or use venv and pip for your project's additional dependencies. Pip has been configured to be venv-only, which is good for the needs of Debian's maintainers, and clarifies what your project has to be responsible for. So, while I haven't needed it yet, I have some confidence that I can get to a reproducible dev environment with the appropriate version of whatever's needed, even if the resolution process is imperfectly automated.

Re: Python environment setup seems complicated and unsolvable

#19
I’ve worked with Python for about a decade professionally and have settled on just always using containers to manage project environments, which is much less messy than many of the other tools in my experience. I was resistant to learning Docker in 2016, but I couldn’t be happier to have done so now. It has also led me away from the Mac as a work device, as Docker for Mac is workable but not as good as being on Linux.

I’m also not surprised that there are still some growing pains with the M1 architecture changeover–when Apple switched from PowerPC to Intel there were software stragglers for a good while.

Re: Python environment setup seems complicated and unsolvable

#20
post #10

IMHO, Poetry is the best we have in the Python dep mgmt space, and it's still endlessly frustrating. It's especially hard to recommend it for newbies looking to get up and running with even a simple ML stack. Check out this thread[1] on the Kafkaesque nightmare that is trying to install PyTorch with Poetry. [1]: https://github.com/python-poetry/poetry/issues/6409

The whole "Python is how science gets done" meme is one of the dumbest things we've allowed to be foisted on otherwise unaware/unsuspecting users (such as the kinds of academics who end up being the victims of the Python ecosystem shitshow). Who knows how many setbacks in science we've suffered, not to mention billions of dollars of productivity lost, sticking to such an unworthy programming system/language/environment. All because, like, colons and significant whitespace make programming so much easier to pick up when you compare it to making someone look at curly braces—which, as we all know is the hardest part of programming.
Post reply on HN