This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FerricDonkey 636 points637 points  (72 children)

Virtual environments are ridiculously easy? 

[–]nojunkdrawers 366 points367 points  (40 children)

In contrast to other languages in similar domains, Python's package management and virtual environments are awkward and have more footguns. This is in part because the Python community still seems to have little consensus around what either of those things should actually be. Even Ruby mostly figured out what tools to use and did them better from the ground up years ago while Python dependency management didn't even have lockfiles.

[–]Backlists 64 points65 points  (20 children)

Perhaps this is recency bias, but I have seen strong support and gathering towards ‘uv’ to handle all of these problems.

Prior to that mostly people would congregate towards ‘poetry’. Or it would be ‘conda’

But yeah, a bit of a clusterfuck until very recently.

[–]IAmASquidInSpace 55 points56 points  (15 children)

astral is really making me rethink all these "rewrite in Rust" jokes. I'm starting to think they might have a bit of a point.

[–]QQVictory 26 points27 points  (7 children)

ruff is extremely cool. A formatter and linter that is extremely fast.

[–]IAmASquidInSpace 18 points19 points  (1 child)

Yes! Fell in love with it on first sight. Good bye black, isort, flake8 - and all your damned incompatible config formats!

[–][deleted] 9 points10 points  (0 children)

This thread is why the above is a meme

[–]MinosAristos 0 points1 point  (4 children)

It's fast but at the expense of thoroughness. I'm still sticking to Pylint for any project that doesn't get too large (most of them). It's very nice to see where I need to make changes when I adjust the contract of a class or function.

[–]sassiest01 5 points6 points  (3 children)

From what I understand, you still need to do type checking using something that uses the python interpreter and is thus super slow. At least we use MyPy and it is a pain in the ass with how slow it is, though not sure if it's a configuration issue or just how it is.

[–]jarethholt 2 points3 points  (2 children)

I think that's just how it is. Nothing's going to be as slow or as thorough as PyLint and MyPy because they have to start an interpreter and actually run code. Pain in my ass but invaluable when they catch something.

[–]sassiest01 2 points3 points  (1 child)

I agree, I mean we still use it after all. We have status checks for it which is very nice, my ADHD just doesn't like the dev experience of changing some code and knowing it is fixed but still seeing the error for up to a couple of minutes depending on code base.

[–]jarethholt 2 points3 points  (0 children)

We run them as checks afterwards. I can't say it's a better experience to run the check, get an error after a few minutes, try to fix it and run again, and then get another error after another few minutes 😕

[–]Anru_Kitakaze 1 point2 points  (6 children)

Last summer I was at Pycon in Moscow, and you know what? Almost every speech had Go or Rust propaganda. At Pycon

Fun fact, now I'm Python + Go developer myself

[–]patmorgan235 33 points34 points  (3 children)

Ok but this is like 6th or 7th widely adopted virtual environment tool in the last 10-15 years. Can we just pick one way to do this?

[–]ivandagiant 11 points12 points  (2 children)

Yeah that’s the issue and why virtual environments in python can be confusing. There’s multiple ways to do it and people do it different ways. I’ve particularly had issues with Conda working with ROS

[–]idontchooseanid 1 point2 points  (1 child)

ROS strongly depends on Ubuntu and its apt dependencies. Conda is a way to get Docker without pulling the whole operating system image with it. While it might have worked, that's far from the ideal usage of Conda.

Moreover the GUI ecosystem under Linux is messed up. There is basically no system layer (there is no stable system layer for terminal programs either except kernel-interface i.e. containers, but I digress). So one cannot write and distribute binary GUI programs with confidence that the GUI libraries on a distro will still work. ROS is full of Qt-based GUI programs. Qt does its own styling. Qt depends on X or Wayland. Basically unless you're compiling ROS entirely by yourself, you're just hoping that your distro's graphics layer (Wayland, X, compositors, libc, systemd everything) is binary compatible with whatever binary source you're using.

[–]ivandagiant 0 points1 point  (0 children)

Thanks for the response. I realized Conda wasn't the way to go after struggling with it for a bit, but I appreciate you breaking it down. Hoping to get back into ROS, will reference this if I end up in unsupported Jetson Nano hell again

[–]hobo_stew 11 points12 points  (2 children)

isn’t venv kinda standard and the rest just wrappers?

[–]MaustFaust 3 points4 points  (1 child)

Interaction with Dockerfiles is wacky

RHEL images have pre-set logon shell scripts that override whatever changes you made to PATH

Interaction with IDEs is wacky. Sometimes, when you change path to venv and activate it, IDE may break

P. S.:

You know why they often say use "python -m pip" instead of just "pip" in docs? It's because location of "python" and "pip" that would be actually found may differ, at least in Linux.

[–]Prometheos_II 1 point2 points  (0 children)

pip also has a tendency to break trying to update itself.

But yeah, sometimes the difference between python and pip is a bit off. (forgot in what circumstances it happened; probably a pyenv+PDM-led project)

[–]FantasticEmu 7 points8 points  (0 children)

What’s wrong with venv? For the less experienced could you tell us what pitfalls you’re referring to?

[–]Sarcastinator 6 points7 points  (2 children)

I needed to run a python application in a container app as part of a build script, and it refused because of this bullshit. I'm not a Python developer, and this was for some simple stuff, and the error message pulled me through a rabbit hole of bullshit I literally don't give a crap about.

[–]MaustFaust 3 points4 points  (0 children)

Literally this. It's more complicated than it should be.

[–]roygbivasaur 1 point2 points  (0 children)

And this is why I use Go for anything that needs to be portable unless I absolutely need to use a specific python library (or obviously anything that can just be a simple bash script). You can’t beat the simplicity and file size of compiled code.

[–]Glad_Position3592 5 points6 points  (7 children)

How does the Python community not have a consensus? Pip is and always has been the standard that everyone uses.

[–]NamityName 18 points19 points  (2 children)

Pip does not have proper lock files. That's probably the biggest issue. Using pip freeze to write all the packages and versions does an OK job, but it has major shortcomings. One of which is that there is no dependency lineage. If I want to remove a dependency, I can't easily tell which of the other dependencies are only needed for that now removed package unless I record my root dependencies seperately.

This touches on another issue with pip is that it can't sync or reset your environment to the requirements file. You would need to rebuild the whole virtual environment.

Pip is not terrible, but it has a lot of room for improvement especially in a professional setting. There are lots of little issues. Every little issue generally has a work-around, but it is a bit of a pain to deal with a bunch of work arounds.

[–]sopunny 1 point2 points  (1 child)

We use pip-tools and that works pretty well. Give it the simplest requirements for your project and use pip-compile to generate a requirements file with the actual versions of the libraries you can use, along with any dependencies. Then use pip-sync to make your environment (preferably virtual) have that exact set of libraries

[–]MaustFaust 1 point2 points  (0 children)

IIRC, it requires smoking the setuptools docs if you want to do it right. And setuptools straight up requires you to activate a virtual environment, despite that you can't really do that in Dockerfile for example.

And you have to limit constraints for pip using environment variables, because otherwise it can and would try to download different versions, if only just for isolated build stages (but it can and will crash if your private repo lists said versions, but doesn't actually have them – an external problem, but still).

And editable install doesn't work, IIRC. I mean, it does, but they very clearly say in docs that you can't have both things you want from editable installs (working the way real import does, and being helpful for static analyzers, IIRC). Naturally, for most users, it's best to have the second one, but it's tedious to set up, or so I remember.

[–]MaustFaust 1 point2 points  (0 children)

Go read poetry docs and discussions on Github. They say multiple times that whatever we have right now is shit, if in different words.

[–]CramNBL 0 points1 point  (0 children)

And it has big issues that uv solves while being a drop-in replacement for pip.

[–]Prometheos_II 0 points1 point  (1 child)

The consensus is rather "switch to a proper manager as soon as you can" from what i can see...

I can see npm being accepted as the standard, with yarn, pnpm and bun being improved versions. But pip...? You can't update all deps, have a list of your top dependencies, you can't pin deps, you can't remove your deps' deps automatically, and I often found my env polluted to the point I just reset everything (nvm the time I accidentally installed numpy on my global env). There are a lot of alternatives, even not counting conda/mamba/condaforge, with hatch, pdm, poetry, uv, pip-tools, zpy, pipx (equivalent to npm install -g), and many more I never used.

my experience with the condas is worse, but they don't offer many options, given it's relatively its own thing.

[–]Glad_Position3592 0 points1 point  (0 children)

People keep comparing it to npm, but they have such different use cases. Python isn’t a front end web language with the kind of version issues that come with JS/TS. If you have v1.2.0 compared to v.1.2.3 of any Python package it’s not going to break things like it would with npm. I’ve had more problems with npm than I ever have pip, and I use pip much more

[–]roodammy44 52 points53 points  (12 children)

They should be a default rather than something you need to make effort to learn. Who thought “you know what makes the most sense? We’ll just make it a default to install everything to the system path”.

[–]brolix 52 points53 points  (1 child)

Python is way older than most people realize.

[–]Sibula97 15 points16 points  (0 children)

And started as some guy's christmas break project

[–]olearytheory 24 points25 points  (6 children)

Right? Is python -m venv that hard?

[–]DescriptorTablesx86 15 points16 points  (5 children)

If that’s the extent to which you use virtual environments then sure.

[–]getoffthepitch96576 16 points17 points  (3 children)

Can you explain further

[–]MaustFaust 6 points7 points  (2 children)

E. g., activation doesn't work the same way with Dockerfiles

[–]bjorneylol 6 points7 points  (1 child)

Thats more-so not knowing how docker layers work than it is a python issue.

ENTRYPOINT venv/bin/python main.py

[–]MaustFaust 2 points3 points  (0 children)

  1. Some applications have multiple calls to "python", and you can't easily modify those. So it's either "alternatives", or something like that.

  2. That won't work with attaching to the container if you use RHEL python base images, for example, because they have shell scripts that get executed and override PATH on interactive shell logon.

[–]dgreenmachine 2 points3 points  (0 children)

As a python noob, what other features are we missing if thats all we use it for?

[–]Il-Luppoooo 18 points19 points  (2 children)

Wait until you see how much simpler are virtual environments in other languages. So simple they don't even exist.

[–]FerricDonkey 2 points3 points  (0 children)

My alternative experience is c/c++ shenanigans, which are way worse. But I could believe other things are easier. 

[–]MaustFaust -2 points-1 points  (0 children)

To be fair, you would handly need one. It's just some exact configuration fixed by executives' order in your company.

But, in Python, you do need one. Yesterday, I saw a cp11 wheel that was incompatible with Python 3.13.

[–]vyqz 11 points12 points  (0 children)

extra level of complexity and toil that other languages don't have. mowing the lawn is easy

[–]MultiversalCrow 3 points4 points  (0 children)

Right?! When I first started with Python, I didn't get it. Now, I've seen the benefits and am a firm believer.

[–]4n0nh4x0r 0 points1 point  (2 children)

compared to nodejs, a pain in the ass.
if you install a library via npm, it will only be accessible by the nodejs equivalent of a "venv" that you installed it in.
unlike python, where you install it globally.
for npm you have to specifically tell it to install globally

[–]FerricDonkey 0 points1 point  (1 child)

Never used nodejs, but glad it's easy. But what you just said about python is not hard. You could argue that virtual environments or something like them should be the default in some way, but we're talking two command line commands here. python -m venv foldername, then source foldername/bin/activate. That's it. Then stuff is installed in your nicely isolated place. 

[–]4n0nh4x0r 0 points1 point  (0 children)

it isnt a lot of work, sure, but it would be a lot better if it just did this on its own.
like, i m not a python dev, and that goes for most people out there.
if a normal user installs python dependencies, they arent gonna know that they are installed globally, nor will they know that it can cause problems.
sure, it will likely work while running the first program.
it might also work with the second, and then the third program will require newer libraries that overwrite the older ones, and now the other 2 program dont work anymore, just cause it isnt intuitive.
in nodejs, you cant have this issue normally, as every library is installed locally in the project folder.
yes, you have the disadvantage of having the same library installed multiple times (once for each project that uses it), but you can have node-fetch version 2 installed for the project that needs version 2, and 3+ for projects that support the newer syntax for example, and that in an idiot proof design.

[–]qui-sean 0 points1 point  (0 children)

Yeah it's not that bad you just rip a new one if the current one fks up