Python environment setup seems complicated and unsolvable
stackoverflow.com
stackoverflow.com
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!) and pipenv, but apparently those are all now out of date and I should be moving to this sixth new tool. I'm sure this time it will be fixed for good.
It's rather a useful tool and I'm personally using it for dependency management and packing for all my projects moving forwards, though for venvs I'm using `pyenv` and the `pyenv-virtualenv` plugin.
Once you figure out your workflow it can be quite nice, but it's figuring it out that's a huge mess in Python at the minute. Hopefully PEP 582 (Python local packages directory) solves it a bit...
Thanks for letting me know (embarrassingly I did load up the PEP page to make sure I remembered the right number but I didn't check its status).
Was hoping that it would make things simpler for smaller projects and newbie developers but the rejection reason is solid.
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.
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.
In academia, everyone pretty much uses Conda to get around these issues, because packages there if you stick to the main channel 'just work' but the licensing is prohibitive elsewhere. Many years ago, you couldn't generally expect to install a Python package on your machine if it had compiled dependencies without installing those libraries yourself with your system package manager and having a local compiler toolchain. That's changed because PyPi introduced wheels which allow you to bundled shared objects, and is why Python is now usable on Windows, but it's not perfect as the this post shows. Wheels generally are available for the most popular OS/architecture combinations - x86 processors, Windows, Mac, and 'manylinux' (an old Linux distribution with low version of glibc to maintain compatibility with newer distros. If you fall outside of that (ARM Mac, want to use a distro with MUSL rather than glibc, etc. etc.) then you basically are on your own and need to compile everything from scratch, and you're going to have a lot of... fun... doing so. In my previous job I worked for a University with a POWER9 GPU cluster, and so we used tools like EasyBuild and Spack to try and manage this, but many packages required manual patches in order to get them working.
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.
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 < 2.5, you will get package c installed in version 2.5…
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.
I think what python misses is things like cargo, go and npm (dare I say it..), tools that handle packages and run your app in context, making that things generally just work.
Might be anecdotal, but I have had way less cross platform/binary issues in other languages. For node things are usually handled very well these days, rust just compiles stuff (or great docs with clear instructions).
It’s not just environments, it’s formatting, linting, types.
I think python used to be ahead in usability, in the last decade it has fallen behind a bit.
It’s still a good language to use because it can do so much, but I can’t say the experience is enjoyable.
Sure, it doesn’t lead to the same exact environment on every machine, but that stuff never ever works anyway at least with portry.
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
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!
Since I use a Arch based Linux distribution, I like to update my (main) Python environment just as frequently: at least once a week. My findings so far:
1. Do not interfere with the system managed packages. I.e. use --user when pip install or make the system python lib dir(s) non-writable for the user
2. If you don't like to switch frequently into another venv, just put the packages that interfere with your main (user) env into separate venvs. These are normally young and intensely developed modules, like e.g. textual, or old non-updated modules, like e.g. ecs, or complicated, cross-language stuff, like e.g. numba, scipy. They will separate themselves out after a while.
3. If nonetheless some local packages interfere with system packages (btw, I hate the --break-system-packages crap), make separate users each with the appropriate environment.
Rinse and repeat.
https://gitlab.archlinux.org/archlinux/packaging/packages/py...
But I was thinking of other Linux distributions. The ones that caused the introduction of --break-system-packages.
And it prevents less a mixing than a shadowing of system packages with local packages.
./venv/bin/python3
Really, could anyone explain why I should care about python environment tools at all? Because we do fine without them.