News for hackers. Stuff that matters.
Re:You don't really need a virtualenv by Traubenfuchs on Thursday February 04, 2021 @07:29AM (#26024783)
Could someone ELI7 why python is struggling so hard with dependencies and dependency management when in the Java world this is a solved problem and just works with maven, which is working so damn well it last got updated in November 2019, and the biggest fight going is whether you should use gradle as client instead of maven to access the same dependency ecosystem?

I had to set up Python projects for some machine learning classes in college and it was a complete mess.

Re:You don't really need a virtualenv by PartiallyTyped on Thursday February 04, 2021 @07:59AM (#26024947)
I am probably in the minority, but my experience is the complete opposite. I had more trouble trying to set up a gradle project in university than I ever had with Python.
Re:You don't really need a virtualenv by tehbeard on Thursday February 04, 2021 @08:45AM (#26025236)
Probably not much of a minority, as gradle's design seems much more friendly to footguns than maven.
Re:You don't really need a virtualenv by loudtieblahblah on Thursday February 04, 2021 @08:44AM (#26025226)
Gradle is a nightmare.
Re:You don't really need a virtualenv by mqus on Thursday February 04, 2021 @07:37AM (#26024823)
I have the opinion that this is because "Deployment" is not a solved issue (or clearly defined and enforced) for Python.

C has shared libraries and static compilation (bundling of dependencies) Java has .jar files which probably contain all your dependencies, go and Rust statically compile to something that has minimal dependencies and python has... no clue. Some packages you have to install via your package manager (in linux), because they have to be compiled against your local libraries, some other dependencies are somewhat included... and if you then try to also develop on the same machine you can choose between your system python libraries or installing them via pip (which makes your system weirder to deploy).

Having said that, I'm no expert in python but I have done some work in it and the deployment question is something that always seemed weird and unexplained to me.

Re:You don't really need a virtualenv by BerislavLopac on Thursday February 04, 2021 @12:19PM (#26027459)
Or to be precise, it is a solved issue -- several times over. After years of meandering, I think it is safe to say that deployment of Python libraries is pretty much resolved in one, general way: we have the wheel/PyPI/pip toolchain, and that's about it.

On the other hand, deployment of Python applications is still unresolved, and there is no single standard method to ensure both compatibility with and isolation from the underlying system in a universal way. There are different methods, from virtual environments (both standard and nonstandard ones like conda), to version managers like pyenv and asdf, to "jailers" like pipx and pyinstaller, to containers; but none of them has yet clearly won.

Re:You don't really need a virtualenv by isignal on Thursday February 04, 2021 @08:29PM (#26031992)
All of the above are suitable for deployment on your cloud servers but not as distribution mechanisms to end users. End users cannot set up virtual envs and pip install stuff into them (which sometimes needs external tools like make).

The candidates for distribution are things like pyinstaller or pex (still not fully mature) but I don't think they are as easy to use as Java jars or Go binaries.

Re:You don't really need a virtualenv by curryst on Sunday February 07, 2021 @08:29PM (#26059847)
I've used pyinstaller. My experience was that pure Python was easy; things that needed to use C shared objects increased in complexity exponentially based on the number of C dependencies. If it's pure Python, you can basically run "pyinstaller <spec file>" and be done. I tried to make PyQt5 work in it, and it was extremely painful. I don't think I ever actually made it work, I think I just gave up. That being said, PyQt5 is probably the most complicated thing you'd ever package with pyinstaller, so it may not be a great test.

> All of the above are suitable for deployment on your cloud servers but not as distribution mechanisms to end users.

virtualenv's are also not a distribution mechanism because they aren't portable (unless that has changed). I can't "distribute" a virtualenv to a host. I can only use virtualenv's to change how pip (or poetry) installs artifacts. Pip is still your distribution mechanism, virtualenv is a runtime customization to change how your distributed artifacts are loaded.

Re:You don't really need a virtualenv by pjfin123 on Thursday February 04, 2021 @11:54AM (#26027152)
This video really helped me understand Python packaging of binaries:

https://youtu.be/02aAZ8u3wEQ

Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @07:40AM (#26024840)
Python should just do what JavaScript does and install all dependencies to a project-local folder.
Re:You don't really need a virtualenv by IgorPartola on Thursday February 04, 2021 @09:02AM (#26025357)
Almost nothing should do what JavaScript does, not even JavaScript. Of all the interpreted languages I’ve used, JS has the single worst ecosystem for running production code. If your experience is primarily with JS, do yourself a favor and try to grok other languages and ecosystems.
Re:You don't really need a virtualenv by HelloNurse on Thursday February 04, 2021 @08:05AM (#26024976)
You are assuming there is a "project", but Python code with massive dependencies can (and often should) be a bare script in an arbitrary folder that runs by invoking the Python interpreter on it, without "installing" anything except missing dependencies.
Re:You don't really need a virtualenv by hctaw on Thursday February 04, 2021 @11:30AM (#26026868)
That's not a bare script then, it's a project with dependencies that need to be installed. This misunderstanding is how you fuck up a developer environment.
Re:You don't really need a virtualenv by hctaw on Thursday February 04, 2021 @11:29AM (#26026844)
I'm surprised this is getting downvoted. This is the only sane way to manage dependencies. They must be relative to the thing you care about.

There are tradeoffs for sure, like the ridiculous sizes of those directories on development machines. But a giant SSD is cheaper than my time resolving dependency issues on user machines.

Re:You don't really need a virtualenv by paulie_a on Friday February 05, 2021 @09:58AM (#26036963)
They essentially are. Not in the actual directory but in the virtual env and not cluttering up your project directory. This is superior to JavaScript in my opinion

No language should replicate anything JavaScript does when it comes to package management

Re:You don't really need a virtualenv by BiteCode_dev on Thursday February 04, 2021 @10:05AM (#26025890)
That's literally what the article is about.
Re:You don't really need a virtualenv by StavrosK on Thursday February 04, 2021 @09:55AM (#26025790)
It does: https://www.python.org/dev/peps/pep-0582/

Though, as the sibling comments say, it's debatable whether it should.

Re:You don't really need a virtualenv by StreamBright on Thursday February 04, 2021 @07:49AM (#26024886)
Not sure if JavaScript has anything that any other language or development tool should copy.
Re:You don't really need a virtualenv by wilsonrocks on Thursday February 04, 2021 @07:55AM (#26024911)
It is a mess... But you can often get a project running an awful lot quicker than in python
Re:You don't really need a virtualenv by notdonspaulding on Thursday February 04, 2021 @09:24AM (#26025525)
True, but if that's the metric we're basing our language choice off of then we should all go back to PHP.
Re:You don't really need a virtualenv by PalzyPunk on Thursday February 04, 2021 @09:55AM (#26025792)
Yeah no kidding. I prefer it as a prototyping language. Unfortunately, I work in networking, and it's become the raison d'etre for our "DevOps". At least we're not using Ansible anymore... :|
Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @08:04AM (#26024968)
JavaScript's package management is significantly better than Pythons:

- There's one tool to use, and it comes pre-installed

- You don't have to deal with virtualenvs or packages from different projects conflicting.

- Native code dependencies "just work".

Re:You don't really need a virtualenv by toyg on Thursday February 04, 2021 @08:35AM (#26025166)
> You don't have to deal with virtualenvs or packages from different projects conflicting.

That's only because you're basically assured there will be conflicts inside any single project. Every time I install anything via npm I get a boatload of warnings about insecure dependencies, which are effectively impossible to fix without breaking the whole mountain of hacks.

There are good deployment stories out there. JS is not one of them.

Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @08:52AM (#26025290)
> That's only because you're basically assured there will be conflicts inside any single project.

That's not an issue with the package management though, that's an issue with the quality of the packages themselves. The JS ecosystem does have issues there. But the tooling itself is good.

Re:You don't really need a virtualenv by dboreham on Thursday February 04, 2021 @08:14AM (#26025032)
That one tool must be yarnnpmgypbabelwebpack?
Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @09:27AM (#26025543)
Babel and Webpack aren't package management tools. I guess there is now yarn in addition to NPM. But NPM works just fine. And furthermore they interoperate.
Re:You don't really need a virtualenv by beckingz on Thursday February 04, 2021 @11:03AM (#26026544)
which gets defined in Yet Another YAML Language
Re:You don't really need a virtualenv by BiteCode_dev on Thursday February 04, 2021 @10:05AM (#26025881)
First, so many tutorials give you terrible information. People don't know about "-m", the "py" command, are told to use sudo and not --user.

The current situation is actually not that bad. With my students, the topic is quickly explained and mastered. But it's not a common occurrence.

However, it is true that it's still not as easy as it could be. Some reasons.

- Python is older than java.

- Python is shipped as part of MacOS and Linux, but using the system Python can cause issues, so it's a trap.

- Python deals with a lot of compiled extensions. Scipy embeds C, fortran and assembly. It's a hard problem.

- The Python project has *tremendously* less resources than java.

- Politics. Lots of it.

- Debian et Red Had packagers made a mess by splitting the python setup in many small packages.

- Python 2/3 transition took attention span from the problem during a decade.

- You often install many python versions on the same machine, which makes things harder.

- Python is used by a huge number of non programmers. Much more than java. This shows in the reported difficulties.

- There are way too many ways to install python. So many combinations of failure modes.

- Microsoft screw up with their store not packaging "py" or the core dev by not packaging it on Unix.

- Anaconda brings as many problems as it solves, and is popular because of enterprise limitations.

Re:You don't really need a virtualenv by Spiritus on Friday February 05, 2021 @06:26AM (#26035174)
The “py” command?
Re:You don't really need a virtualenv by kcon on Friday February 05, 2021 @11:32AM (#26038084)
I think that is referring to the Python launcher utility for Windows: https://docs.python.org/3/using/windows.html#python-launcher...
Re:You don't really need a virtualenv by StreamBright on Thursday February 04, 2021 @07:49AM (#26024884)
Java is a self hosted language and has very little dependency on C/C++ or something similar.

Python is glue language for C/C++/Fortran/Rust/etc. projects. Most of the valuable packages in Python in fact C++ projects (like Tensorflow, Pandas, etc.). When you are talking about Python dependency management you are talking about the Cartesian product of the packages you are depending on, their dependency in terms of compilers and header files. It is not hard to run into missing .h files while trying to install these dependencies. This situation was improved significantly a while back with the WHL files.

Anyways this whole article does not make too much sense, I am using Python for 10 years professionally and never run into the concept of nested venvs let alone somebody trying to use that in production.

Re:You don't really need a virtualenv by cdavid on Thursday February 04, 2021 @07:51AM (#26024898)
Compiled dependencies is indeed one of the main reasons. Another one is lack of enforced, static metadata because python started before most other languages.
Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @08:11AM (#26025012)
> It is not hard to run into missing .h files while trying to install these dependencies.

They would be if python provided the .h files in the packages rather than expecting them to already exist on the system.

Re:You don't really need a virtualenv by rini17 on Thursday February 04, 2021 @08:24AM (#26025098)
That's just dangerous band-aid. If there is a mismatch between bundled .h and installed system library, you'll get (in better case) linker error, or runtime problems.
Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @08:50AM (#26025276)
Well I was assuming the actual library would be bundled too: not just the headers!
Re:You don't really need a virtualenv by wiredfool on Thursday February 04, 2021 @08:59AM (#26025341)
At that point, you should just be installing a binary wheel.

(Nb I’m a maintainer of a python project that’s difficult to build, and the number of issues we get that start: can’t install because foo.h can’t be found is very high, even though there’s other explanations closer to the end of the failed build)

Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @09:24AM (#26025531)
Does that not happen by default when you try to install a package? And if so, why not?
Re:You don't really need a virtualenv by wiredfool on Thursday February 04, 2021 @12:30PM (#26027600)
There are several reasons that people don’t get the binary wheels, but a lot of the time it’s either pinned dependencies where they’re requesting an old version while running 3.9, that window between a new python release coming out and our quarterly release schedule, or an unsupported arch for binaries like Alpine, the m1 macs, random android.
Re:You don't really need a virtualenv by nicoburns on Thursday February 04, 2021 @01:25PM (#26028254)
Ah I see, that makes sense. I believe Node modules typically fall back to building from source in those cases. Which can be a little slow, but generally works reliably.
Re:You don't really need a virtualenv by wiredfool on Friday February 05, 2021 @04:10AM (#26034449)
I can see that, but we rely on a bunch of system libraries (libjpeg/zlib, + optional libtiff/freetype/etc, and python headers as well). Pretty much by definition, if we don't provide binaries, it's not going to be that simple.

I'd say maybe 25-50% of developer linux workstations have the appropriate packages and will compile out of the box, and if they don't, it's almost always a one line command to install them with a package manager. We've got instructions or docker images for testing for most major linux distros.

MacOS is probably in the 5-10% range for successfully compiling out of the box, some of the headers ship with MacOS, but there are a couple steps to go through. M1 is still a WIP in the python packaging community.

Windows... 0% compile out of the box. You have to set it up, download dependencies and so on. There are at any one time a handful of people who can compile for the windows platform, and a smaller handful of people who can debug problems.

Now, to be fair, I think this project is probably in the most complicated 1% of python projects from a packaging point of view. There are probably more complicated ones, and the only two complications I'm aware of that we don't have to deal with are 1) The chicken and egg of if we break an update we lose the ability to update all the other packages including our own (pip) and 2) GPU drivers.

Re:You don't really need a virtualenv by wiredfool on Tuesday February 09, 2021 @01:37PM (#26081003)
Following up, two other things we don't do are 3) Fortran dependencies and 4) Rust.
Re:You don't really need a virtualenv by gruez on Thursday February 04, 2021 @09:01AM (#26025352)
That's just the precompiled whl files
Re:You don't really need a virtualenv by varjag on Thursday February 04, 2021 @08:26AM (#26025106)
That's a terrible idea, all you'd end up with is a bunch of headers mismatched to actual system libraries.
Re:You don't really need a virtualenv by suifbwish on Thursday February 04, 2021 @08:25AM (#26025103)
My secret is to build a new computer every year and keep images of the old ones with all my packages and libraries. Trying to run a tensorflow GitHub library from 2013? Easy just use the computer with that image
Re:You don't really need a virtualenv by Dryondristica on Friday February 05, 2021 @08:35AM (#26036106)
People always criticise Python for dependency management, but I've never found it to be that bad. virtualenv with requirements.txt has been completely fine in my experience with medium-sized projects. If necessary you can pin versions with a separate version-locked requirements.txt, and populate that from a base requirements file.
Re:You don't really need a virtualenv by mejutoco on Saturday February 06, 2021 @12:06PM (#26047877)
Came here to say exactly this. This has been my experience as well
Re:You don't really need a virtualenv by maliker on Thursday February 04, 2021 @08:51AM (#26025280)
My ELI7 understanding is that python installs required modules (libraries) at the system level by default, and doesn't have good support for installing modules into local directories like node/C/java/etc. does, which leads to conflicts. Users have to find a set of modules that support all of the scripts on their system. The current workaround is to isolate each script's requirements, but there are a ton of competing tools to do this (virtualenv, pipenv, poetry, etc.), so it's hard to choose the "best" isolation solution.

One reason people like PEP 582 is that, by being something built into the interpreter, it will reduce a lot of the confusion over which isolation tool to use.

Part of the problem, which local installs won't completely solve, is that the python interpreter is still changing fast enough that modules are having trouble keeping up. E.g. tensorflow is still working on python3.9 support [1], and now we'll see python3.10 in the next couple weeks. Even with local installs we'll have to be careful to use the right interpreter.

Another piece of the problem, which is also kind of a good thing, is the huge size of the python module ecosystem. I've got python scripts with over a hundred requirements. It saves me from writing a lot of code, but resolving the requirements is a challenge. The pip package manager has recently added a dependency resolver, which has helped a little make sure everything can work together.

The only surefire ways I can think of to make this huge module ecosystem interoperate cleanly are (1) have every module support every other version of every other module and interpreter (insane amount of work, won't happen) or (2) have simpler interop interfaces like the unix shell convention of only passing strings between programs, but that would take away a lot of the ease-of-use of passing rich objects around between modules.

[1] https://github.com/tensorflow/tensorflow/issues/44485

Re:You don't really need a virtualenv by peterthehacker on Thursday February 04, 2021 @11:06AM (#26026585)
> I had to set up Python projects for some machine learning classes in college and it was a complete mess.

Did you use conda (anaconda/miniconda) or pip?

Re:You don't really need a virtualenv by N1H1L on Friday February 05, 2021 @03:19PM (#26040695)
Tell me about it. I had cudatoolkit installed, and then followed every single PyTorch installation instructions, and then still it insisted that I should get the CPU version, not the GPU one.

I ultimately fixed this with going to the conda files list, and choosing exactly what I needed. Not straightforward at all.

Re:You don't really need a virtualenv by ingas on Thursday February 04, 2021 @11:03AM (#26026543)
> I had to set up Python projects for some machine learning classes in college and it was a complete mess.

"Machine learning" here is crucial I suppose. Sklearn, keras are big beasts.

Would you install something like django/flask site than I don't think you would had any problems.

Re:You don't really need a virtualenv by paulie_a on Friday February 05, 2021 @09:53AM (#26036893)
I cannot fathom where python is struggling is with that. Pip and a requirements file that can be pinned with version numbers

It's super easy, barely an inconvenience

Gradle is a hot mess and JavaScript is the just a complete shit show

Re:You don't really need a virtualenv by collyw on Friday February 05, 2021 @06:06AM (#26035065)
We should have stuck with Perl. I never came across the same problems with CPAN.
Re:You don't really need a virtualenv by 0xbadcafebee on Friday February 05, 2021 @08:53AM (#26036290)
CPAN I think only recently got virtualenv-like support; before it was much worse and a pain. Where CPAN modules shine are they're more stable, backwards compatible, and extensible. Modules whose last release was 15 years ago work fine today, and new modules are extended on them.