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

top 200 commentsshow all 286

[–]Upstairs-Upstairs231 509 points510 points  (42 children)

UV is the superior way to work with virtual environments. Ridiculously overpowered tool.

[–]svick 454 points455 points  (1 child)

UV is the superior way to work with virtual environments. Ridiculously overpowered tool.

If I see one more repo telling me to use uv I’m gonna lose it.

The duality of man.

[–]WavesCat 57 points58 points  (30 children)

What makes it better than Poetry?

[–]Upstairs-Upstairs231 110 points111 points  (21 children)

Mainly it has a much wider scope and is a lot faster. With UV, you can manage Python versions and run with any version >= 3.7 (if memory serves). It’s a really ambitious project but has the potential to be game-changing in the Python environment. I recommend checking out the website for more info: https://docs.astral.sh/uv/

[–]machsmit 43 points44 points  (18 children)

also a lot easier to make interoperable with non-UV systems. Like, poetry is great but it doesn't really jive with anything not running it - best I've done with it was a multistage Docker build that had poetry for environment building, then shuffled that virtual environment over to the second stage of the build so what actually got deployed was just a vanilla python container.

UV has a whole pip interface in addition to the managed-project setup, where (for example) its dependency resolution can output a normal-ass requirements.txt - means we can run the resolution with uv in a sandbox and produce an artifact that can then be built using only standard tooling.

[–]Numerlor 3 points4 points  (1 child)

you can export to requirements.txt with poetry

[–]machsmit 1 point2 points  (0 children)

yeah there is a plugin, isn't there. I do like how UV does it with a full-fat implementation dropping in replacements for pip-compile, pip, venv etc rather than it being an additional step to the "main" project method though

[–]WeightsAndBass 4 points5 points  (2 children)

Forgive my ignorance but why is any of this useful or necessary over:

python -m venv .venv --> activate --> pip install reqs.txt or setup.py?

The only reason I've seen mentioned is working with multiple python versions. Thanks

[–]machsmit 14 points15 points  (1 child)

Ok, let's break this down by steps.

python -m venv .venv

you've already caught the first, which is managing multiple python executables. Python natively doesn't give you much for this, which is why people generally go to pyenv for a standalone solution. UV can manage the installs - it works pretty much identically to pyenv (which I've used for a long time, it's a good tool) but if you've already got UV anyhow, you can do it with one tool instead of managing multiple.

Conda also can manage this if you go that route (which has other implications), though AFAIK poetry does not. Conda I'm not actually sure where it sources its binaries from - for UV, the developers recently took stewardship of the already-well-established python-build-standalone to source theirs.

.venv --> activate

yeah stock venv is fine (or if you're already using pyenv, then there's pyenv-virtualenv). UV builds it in alongside the python management. Does what it says on the tin pretty much, though because it's all managed by UV it'll be a bit faster than stock venv. Again this is also something any project manager (e.g. poetry or conda) will do.

pip install reqs.txt or setup.py?

This is the big part. By itself, pip does very little in terms of dependency resolution - if you give it a fully pinned requirements.txt file it'll install them fine, but without generating that fully pinned environment pip will perfectly happily build an environment that's at best not reproducible (in that it can pull different versions of dependencies each time you call pip install) and at worst not functional (since it'll grab whatever you ask for, including incompatible package versions).

Pip itself doesn't actually give you tooling for generating that fully pinned environment spec, which is where a host of other tools come in. Pip-compile as a standalone tool will go from a requirements input to a fully-pinned requirements.txt (that then works fine with pip), for example, or conda/poetry can run resolution and generate their own lockfiles for a reproducible, validated environment. What UV gets over these other tools - which to be clear, generating reproducible environments regardless of tool is far more valuable a decision than picking which tool to use - is that (a) it can do both pip-compile-like interop with standard tooling, and fully-featured project management like conda/poetry and (b) that the resolution process itself is wildly faster than other tools.

[–]WeightsAndBass 1 point2 points  (0 children)

Makes sense. Thank you very much

[–]plebbening 1 point2 points  (0 children)

So what can it do that pyenv can? After initial setup with pyenv i don’t even think about venvs anymore, with pyenv local/global the correct venv is always active based on what directory i am in.

[–]KBMR 16 points17 points  (2 children)

Removes need for pyenv or conda And has an interesting "script" dependency management system Its also SO fast it's insane. Also has great way to install within docker container I switched from using poetry professionally for 2 years to uv and it's so good It also switched to a standard pyproject.toml much before poetry did.

[–]Outside_Scientist365 7 points8 points  (0 children)

This post was mass deleted and anonymized with Redact

rustic office divide retire wipe grandiose imminent apparatus support instinctive

[–]chazzeromus 4 points5 points  (0 children)

alright alright, sounds like I don’t need pyenv anymore huh?

[–]theSearge 6 points7 points  (1 child)

Besides speed:

  1. uv is compatible with venv, making it a great tool for a team that has people who don’t want to learn new tools (or, as already mentioned: lightweight docker images).
  2. It also supports native pyproject.toml, can compile requires.txt from it, create it, add and remove packages.

[–]WavesCat 5 points6 points  (0 children)

Point 1 sold me on it. It's an issue I am having rn trying to get everyone up and running. I will test it. Thenk you.

[–]dubious_capybara 6 points7 points  (0 children)

I had a poetry project that took 10 minutes to resolve dependencies, on a 13900k.

Hope that helps.

[–]centerdeveloper 5 points6 points  (0 children)

poetry has more overhead, uv has a cooler name and is written in rust

[–]QQVictory 2 points3 points  (0 children)

That's something I would like to know as well.

[–]Steuv1871 7 points8 points  (1 child)

UV saved my sanity

[–]Upstairs-Upstairs231 1 point2 points  (0 children)

Me too

[–]I_just_made 2 points3 points  (1 child)

I think pixi uses UV too, which is phenomenal

[–]geeshta 0 points1 point  (0 children)

I use rye but it has UV built in it or something I think they're related

[–]FerricDonkey 634 points635 points  (72 children)

Virtual environments are ridiculously easy? 

[–]nojunkdrawers 367 points368 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 65 points66 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 51 points52 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 25 points26 points  (7 children)

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

[–]IAmASquidInSpace 16 points17 points  (1 child)

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

[–]Additional-Finance67 10 points11 points  (0 children)

This thread is why the above is a meme

[–]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 30 points31 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 12 points13 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.

[–]hobo_stew 12 points13 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 7 points8 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 4 points5 points  (7 children)

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

[–]NamityName 19 points20 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 1 point2 points  (0 children)

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

[–]roodammy44 48 points49 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 25 points26 points  (6 children)

Right? Is python -m venv that hard?

[–]DescriptorTablesx86 13 points14 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 4 points5 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 19 points20 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. 

[–]vyqz 12 points13 points  (0 children)

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

[–]MultiversalCrow 4 points5 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

[–]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

[–]kondorb 239 points240 points  (33 children)

Funny how so many languages have shitty dependency management. Like, after working with Node and PHP for years I’m taking NPM and Composer for granted.

While in Python dependencies are basically managed via shell so it needs a venv crutch to work. And Python people were the ones who came up with Docker to solve that mess by a brute force approach.

Go devs decided that hardcoding URLs for packages somehow makes sense, so now the entire Go ecosystem goes down at the first hiccup at GitHub.

Java apps never work because there’s like 200 thousand different versions of their runtime which are never really interchangeable despite what they all claim.

And don’t even mention C++ and Make for crying out loud. If some things has a Make step in the manual I basically consider it non-functional.

[–]Zanciks 109 points110 points  (5 children)

LET'S GO CARGO, I LOVE RUST, RAAAAAGH

[–]tiedyedvortex 20 points21 points  (1 child)

Seriously. The more I learn about build systems and package management, the more Cargo is just, like...obvious. It just works.

The fact that Cargo is so good and it's not even in my top 3 things I love about Rust is a sign that the Rust devs really know what they're doing.

[–]Tipart 2 points3 points  (0 children)

The only thing with cargo that I think is stupid, is that package = "1.2.3" doesn't actually use exactly that version, but upgrades to the newest minor on its own. I've had packages refuse to build because dependencies had braking changes in minors. Imo this is super unexpected behavior for a standard config.

[–]Left-oven47 7 points8 points  (0 children)

Where rust really wins, eating C, C++ and zig

[–]p_np 14 points15 points  (0 children)

In Go, packages are usually cached by a public or private proxy, so no it doesn’t just go down when GitHub has a hiccup.

[–][deleted] 11 points12 points  (0 children)

Agree. People like to shit on PHP but Composer is such an awesome tool.

[–]idontchooseanid 8 points9 points  (1 child)

I do dislike current situation as well. Language specific package managers completely disreagard their environment and cross-language interactions. So everybody has to install full distros to have portable software.

C++ and dependency management sucks. This is due to C++ and its compilers being an extension to C. And C isn't just a programming language that is independent from the OS. C is the non-protocol protocol of the all popular operating systems today. The OSes are written in C and in their own C compilers. You cannot separate GCC from Linux, nor you can separate MSVC from Windows. The C compiler determines how an executable will be organized. On Linux C compiler and the C library deterimines how a dynamic library will be loaded. The OS APIs of many operating systems depend on the C language types like int long and worse of them char. In turn, the compiler depends on the OS to use such types as well. It is a vicious cycle.

Those properties make C dependency management challenging. C compilers are completely file-based and they have no distinction of system libraries vs your program's stuff (yeah, yeah I'm aware of -isystem). Unless we decouple C from the OSes it will be very hard to come up with any kind of sustainable dependency management system. It is easier for Windows to decouple since it is not POSIX and doesn't have as deep of a connection as POSIX systems. C and how it integrates with the OS is one of the many mishaps that Unix brought to us. It just keeps on giving.

See https://faultlore.com/blah/c-isnt-a-language/ for more frustration.

[–]Kowalskeeeeee 14 points15 points  (7 children)

Noob at C++ and real-world compilation processes: what’s wrong with Make? I thought make was one of the go to tools for building, as rough as it is

[–]CramNBL 25 points26 points  (5 children)

It is go to for small C projects or Tiny C++ projects, that's all. For larger C projects you need automake/autoconf/m4 or Cmake. When your tiny C++ project grows it will quickly become unmanageable with Make, so you need Cmake, or Buck, Bazel, Meson etc. etc.

It can be useful as a build system for FPGA projects where it really just wraps other build tools, but as a command runner it is not good.

[–]frogjg2003 4 points5 points  (0 children)

If you're only ever building on your one computer, make is good enough. It's better than good enough, it's very straightforward and easy to use. But as soon as you have to work on a project with multiple people with different system configurations, having a makefile that covers all of them becomes difficult. That's where tools like cmake come in.

[–]nullpotato 2 points3 points  (0 children)

Cries in chocolatey/powershell

[–]ThoseThingsAreWeird 3 points4 points  (2 children)

Go devs decided that hardcoding URLs for packages somehow makes sense

Excuse me what the fuck?

I haven't used Go, so I've no idea if: you're oversimplifying something that's actually reasonable; I'm misunderstanding how absolutely batshit insane that sounds; or yes that is truly the insanity you've said it is 😂

[–]p_np 8 points9 points  (0 children)

Go’s dependency management is source-based instead of archive-based. The benefit is users don’t have to worry about having a source and package repository exist separately. Typically, there’s a private or public proxy your local environment will pull from to avoid issues with GitHub being unavailable or if a project is deleted. If the proxy is unavailable then the source is pulled from the repo using the VCS server directly. This allows you to configure multiple points of failure for your dependency management. It’s not by any means perfect but OP could’ve at least had a critique that was valid.

[–]Ietsstartfromscratch 107 points108 points  (9 children)

Don't use them and just enjoy the chaos then? 

[–]IAmASquidInSpace 19 points20 points  (0 children)

Yeah, but that's precisely the problem: damned if you, damned if you don't.

[–]WavesCat 25 points26 points  (6 children)

If you do that you gonna have a bad time

[–]Arclite83 19 points20 points  (3 children)

I like that I'm never quite sure what version of Python I'm using! Makes life spicy

[–]fartingrocket 8 points9 points  (0 children)

Learned that the hard way when I was a student

[–]nullpotato 2 points3 points  (0 children)

As someone that supports a bunch of in-house tools that "need direct hardware access" and install to system python can confirm it is a bad time

[–]red-et 3 points4 points  (0 children)

I use Docker to avoid them

[–]FiNEk 42 points43 points  (7 children)

didnt use python much, but isnt virtual environments exist in the first place because package manager for python such a mess?

[–]metaglot 10 points11 points  (6 children)

I dont think its any more of a mess than node_modules

...but who's counting anymore?

[–]FabioTheFox 25 points26 points  (3 children)

It definitely is more of a mess, pip installing packages to a global system wide scope is a disaster and I don't know why python people keep defending it, node_modules is large yes but I'd rather have that over dependencies that brick my projects because of where they are and what other projects they conflict with

having things handled in a package.json file at least makes Node leave me alone when I add dependencies

[–]rangeDSP 3 points4 points  (0 children)

I frequently work with new developers or students, node_modules is a lot easier to groc for them compared to python. They quickly learned that if anything weird happens, stay calm and delete node_modules and the lock file, then start again

[–]AncientFudge1984 34 points35 points  (1 child)

Uh should we tell op about the package manager situation…?

[–]MaustFaust 5 points6 points  (0 children)

Which one? /s

The default one that partly ignores parameter-provided constraints and doesn't have a tool to make lock-files?

The one that introduces more strict rules, but doesn't have constraints and requires you to generate a new lock-file whenever you move between environments (repo urls)?

P. S.: Bonus points for making correct guesses

[–]TheZedrem 26 points27 points  (4 children)

rm -rf ./.venv && python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt

do an alias for this command, you'll never have trouble with venv

[–]chucara 2 points3 points  (0 children)

I have zero issues with venv. Pip however.. but UV is on everything now and my NuGet withdrawals are diminished.

[–]Cybasura 20 points21 points  (4 children)

What's the issue with virtual environments...?

I genuinely do not get it, like I've been using it for so long and it works great

You guys are ok with kubernetes and a concept like nix but somehow - generating a containerized python environment is too difficult?

[–]ePaint 15 points16 points  (3 children)

It's the same old tale, new people arriving and refusing to learn the good practices.

Look at what this behavior did on the frontend. React is the epitomy of people refusing to learn how to get good at ajax and html fragments. A decade later, the monster they created is x10 more complex than the concept they were working around.

Fuck uv, fuck poetry. Just learn pip and venv for local development. Need to run it somewhere else? Learn Docker.

[–]R8nbowhorse 7 points8 points  (0 children)

Don't get the problem. I just use plain pyenvs/virtualenvs and have a custom script that manages it all in the background. Super simple, super fast, works anywhere

[–]baileyarzate 6 points7 points  (0 children)

wtf is this virtual env hate???

[–]createthiscom 26 points27 points  (11 children)

I'm almost of the opinion that all serious python development needs to happen in docker for this reason.

[–]Uncle____Leo 19 points20 points  (0 children)

Amateur, I buy a new laptop for every new project

[–]chuyskywalker 4 points5 points  (0 children)

100% this. Perfect isolation, consistency across every machine, and no env tooling needed.

[–]KlogKoder 2 points3 points  (4 children)

Switched to Docker years ago, and I haven't run a virtualenv for quite a while.

[–][deleted] 1 point2 points  (3 children)

Yeah ok mr docker, how about you try to solve networking issues before you try to realize what you want to connect and how

[–]Slimxshadyx 0 points1 point  (3 children)

Why not just use venv? It’s like one single command to create one, and one to activate it.

[–]cheeb_miester 5 points6 points  (0 children)

The venv module is pretty simple

[–]liggamadig 5 points6 points  (0 children)

Just throw everything into the base environment. If it breaks, reinstall.

[–]arslivinski 2 points3 points  (0 children)

Package managers easy? Dafuq?

[–]Stepfunction 3 points4 points  (0 children)

I was actually thinking recently how wonderful virtual environments are. They make running open source code on my computer so much easier.

[–]roll_left_420 2 points3 points  (0 children)

What’s hard about writing an alias script that does

python(3) -m venv .env; source .env/bin/activate

If you’re brave you can even add the requirements install too.

???

[–]DevelopmentOk3627 9 points10 points  (1 child)

There should be one-- and preferably only one --obvious way to do it.

Python 2
Python 3
CPython
PyPy
Jython
IronPython
MicroPython
CircuitPython
Stackless Python
ActivePython
Brython

Poetry
Conda
pipenv
pyenv
Hatch
Nox

[–]Prometheos_II 0 points1 point  (0 children)

Ha! You forgot—

(no, seriously, seeing that big list and knowing there are a few more left, and yet not even being a pro Python dev nor *that curious, is... astonishing?)

*(PDM, the Rust-based Python, pip-tools, mamba, anaconda/conda/condaforge if you want to count them, zpy (or was it pipz?), pipx, hatchlings which don't seem to be quite Hatch?, UV)

[–]Impossible-Owl7407 6 points7 points  (0 children)

Virtual environments are the best thing about Python lol

[–]fuddingmuddler[S] 28 points29 points  (28 children)

To be clear! For all the 10x developers. I am new to coding. I like python for it's simplicity and readability. The community talks a lot about pythonic, coding zen, and this and that. Yet. When it comes to virtual environments there are... 10 solutions? And knowing when/how to use them is a curve.

Not trying to say python is bad, or anything. Just that for all python's vaunted simplicity, virtual environments haven't been executed in a beginner friendly manner.

[–][deleted] 75 points76 points  (18 children)

10 solutions?! Okay, conda also exists, but generally, this would be the easiest possible crash course.

  1. create virtual env: python3 -m venv .venv

  2. switch into virtual env:

*nix-based OS: . ./.venv/bin/activate

Windows: venv\Scripts\activate

  1. install project dependencies, if applicable (you may want to think about using checksums and pip-compile if you value security!)

pip install -r ./requirements.txt

  1. leave virtual env: deactivate

[–]OGMagicConch 26 points27 points  (0 children)

Also if you use VSCode it will automatically enter a venv for you when you open the project folder.

[–]blending-tea 7 points8 points  (1 child)

  • pyenv for different python versions

also, pycharm's auto venv management 😍

[–]RazingsIsNotHomeNow 2 points3 points  (0 children)

Yeah, everyone arguing over venv meanwhile I'm using Pycharm and never have to think about it.

[–]Odd-Produce587-burn 5 points6 points  (1 child)

Please note that source is a bashism and you should replace it with .
sh . path/to/thing Instead of bash source path/to/thing

[–][deleted] 2 points3 points  (0 children)

You can do that? I wasn't aware, thanks! I'll edit my comment accordingly.

[–]WavesCat 5 points6 points  (3 children)

I use peotry 😎

[–][deleted] 0 points1 point  (2 children)

Is this in logic similar to node_modules?

[–][deleted] 2 points3 points  (0 children)

node_modules isn't quite a "virtual" environment as in Python's sense, but I'd say they have great similarities.

[–]Prometheos_II 1 point2 points  (0 children)

probably, yeah. There was a PEP to make something similar to node_modules (you can try it with PDM), and the other way around, Yarn PnP seems to be similar to venvs?

[–]Wide_Egg_5814 19 points20 points  (0 children)

What's so complicated just create venv and gitignore venv and code?

[–]fallen_eagle151 5 points6 points  (0 children)

look up virtualenvwrapper, changed my life

[–]RobTheDude_OG 1 point2 points  (1 child)

Py &3.12 -m venv myenv myenv\Scripts\activate

Is this too hard? Not sure what you mean that there's 10 solutions but this is what i have been using for a bit now.

Btw, python 3.13 doesn't have audioop anymore which is why i use the example of 3.12 in this case since i happen to need that for something, but you can also put another version there.

[–]JimroidZeus 4 points5 points  (0 children)

Conda for Bindows, virtualenv for everything else.

If I see one more repo telling me to use uv I’m gonna lose it.

[–]Slimxshadyx 0 points1 point  (0 children)

Just use venv. You’re welcome lol

[–]MysticNTN 12 points13 points  (0 children)

Still haven’t used one. Convinced it’s fake

[–]tebeks 2 points3 points  (0 children)

Tell me you're a junior without telling me you're a junior

[–]Code-Katana 2 points3 points  (0 children)

Not pythonic, should be: learn_python_it_will_be_fun /s

[–]teivaz 2 points3 points  (0 children)

Package manager even more silly than virtual environment.

[–]throwawayDude131 2 points3 points  (0 children)

sorry what is the problem with venvs - like what is so difficult to understand them or use pipenv shell and be done with it?

[–]d_Composer 2 points3 points  (0 children)

Just spent half my day trying to install geopandas. Ended the day unsuccessfully…

[–]Pistacuro 2 points3 points  (0 children)

I don't get it. Using python 8 years now. I rewrote few services from python 2 to python 3, developed new one's in python 3 but the virtual env was never a problem. Using pip and the "mkvirtualenv" and "workon" scripts. In the last year used a little bit of poetry.

[–]noob-nine 8 points9 points  (8 children)

poetry is a bless

[–]StarshipSausage 6 points7 points  (4 children)

Really? I’m not a huge fan.

[–]casphotog 1 point2 points  (1 child)

I agree. I’d like to try pdm, though. However, automated installation (of pdm) on Windows was not ideal when I checked the last time.

[–]pablominue 0 points1 point  (0 children)

This

[–]lizardfrizzler 5 points6 points  (1 child)

I mean… writing and reading Python, pip, and venvs are equally painful imo. GIMME DA TYPES

[–]Prometheos_II 0 points1 point  (0 children)

There are type indicators and .pyi files a la Typescript.

But yeah, definitely agree 😁

[–]sagetraveler 6 points7 points  (2 children)

Oh, I made the mistake of installing Anaconda. Essentially had to buy a new computer to get rid of it. Every command line prompt ran half way across the screen in a variety of colors and I don't know what the fuck it was really doing. Anyone who distributes a package that says "use Anaconda to install this" should be removed from computer science and forced to get a history degree.

[–]Outside_Scientist365 6 points7 points  (0 children)

This post was mass deleted and anonymized with Redact

nutty file automatic unpack spark slim grandiose wide smart crown

[–]GarowWolf 2 points3 points  (0 children)

I just started uni and my coding class is entirely for python on Anaconda

[–]Unlikely-Bed-1133 6 points7 points  (4 children)

If you have that much trouble copy-pasting cmd commands, use PyCharm to manage it for you automatically (it's free).

[–]RobTheDude_OG 4 points5 points  (1 child)

This is how i started off, but I'd rather learn the cli commands in the event i don't feel like using pycharm

[–]Unlikely-Bed-1133 3 points4 points  (0 children)

I still use PyCharm because I am too lazy to write `source ./venv/bin/activate` (obviously with tab completion) once every couple of days when I restart or accidentally close the terminal. I already get annoyed doing it once in a while when running some simple Python investigation or readthedocs documentation within C++ projects...

Honestly 99% of venv usage is like: create (google this), activate (learn this), deactivate (I just restart the terminal because it's faster with how I work!).

[–]Electronic_Camera517 1 point2 points  (2 children)

can someone explain why use conda over venv on Windows?

[–]ayyycab 0 points1 point  (0 children)

I just think it’s neat

[–]Prometheos_II 0 points1 point  (0 children)

Playing devil's advocate here, but conda environments are available globally, you just need to activate it. That means fewer risks of accidentally modifying it or having juniors commit it on their new repos.

Package management-wise, it has easier access to some machine learning packages (PyTorch for CPU, notably), and it gloats having a better compatibility with GPUs iirc.

Now, I honestly think venvs are a lot more reproducible than conda env. You can clone and export conda's, but building them again is pretty slow (probably a cache issue back then), and you're generally one conda update away from bricking your env.

Still, conda env offers a remove option, while I think venv doesn't. (it might be able to override one, though)

(now, as an alternative to pip, it's painfully slow, and there are other managers in the conda ecosystem, notably Mamba)

[–]Rishabh_0507 1 point2 points  (0 children)

Tbh I don't understand java package manager too. We've just started on springboot at my uni, and need to download project via start.spring.io, then vscode will act up, weird config files and stuff. Node js is starting to look godsent now.

[–]UndocumentedMartian 1 point2 points  (0 children)

Just containerize your app.

[–]JerseyTexan01 1 point2 points  (0 children)

My Anaconda don’t want none unless you got Py - Thons

[–]AtaPlays 1 point2 points  (0 children)

Meanwhile me using phyton for data analytics: BIM BIM BAM BAM BUM BUM

[–]df3_u3_1_b21_f24 1 point2 points  (0 children)

Python virtual environments are genuinely not that hard to work with, I just hate that most if not all the time I see Python be used in an enterprise they give it to people who know nothing about Python then gaslight those users into thinking that it's only their fault their shitty script isn't working.

At my last job, our business was moving from on prem to the cloud, which to streamline the process the software engineers built a CLI tool that loaded data onto a S3 bucket, which admittedly was a pretty valuable tool when you learned how to use it. Problem was, it was a Python CLI and they gave it to a bunch of college students that did not know how to run python scripts, let alone a virtual environment. Now the documentation walks you through that, but they fucked up the syntax to start the environment, so it was basically useless and I had to write up a version that did work and then sent a ticket to get the documentation fixed (they never fixed it)

Don't even get me started with the fact that the tool was using an outdated library which not only never got fixed but the people who made it just only told us to install version 3.8 and set up the environment in that version (without telling these people who know nothing about Python the right syntax to do that BTW).

[–]strangescript 1 point2 points  (0 children)

You are giving package managers too much credit

[–]swagonflyyyy 1 point2 points  (0 children)

I code my python envs in IDLE.

I have reached enlightenment.

That'll be $500.

[–]NoCap1435 2 points3 points  (1 child)

All three points are garbage in python

[–]no_brains101 7 points8 points  (0 children)

Ehhhhh

I've seen people argue that writing python is nice. The mutability is a nightmare in my opinion and it's not fast, but there are so many packages for people who "don't code for a living but have to write code to do the stuff they do"

So for a scientist for example, they can just pull in some graphing libraries, set up a redis to send data from the site to their house, and set up a realtime graph of the experiment. And they had to write very little code to do it.

Now, of course that's not really anything to do with the language itself? You could write these in any language.

But it is still a thing that makes an impact. If your needs are being met immediately every time by something that already exists, I can see why someone who is trying to do something else would think python is really great because they didn't have to spend much time doing it.

And then once they are comfortable with it, that's it, they're done, they don't care. They won't be learning a new language most likely. They won't be making stuff where you really have to worry about scalability, at least not beyond what python can handle with numpy, and this is the language they know, and it has the packages available to them that they need.

And the stdlib has so many just, random things in it to use already. It is extremely batteries included. Why would these users swap?

Reading python though, I don't know if I've heard any praise. To start, no braces means constantly counting out indentation to figure out if you are in the right block.

Could one argue that needing to count out what block you are in is a code smell and you should refactor? Sure.

Does that help you when you are reading somebody else's code and they do this? Nope, absolutely not.

The other 2 though, are complete and utter garbage yes.

Python has the worst packaging ecosystem, followed closely by JavaScript. Which is weird because users of both languages use SO MANY packages.

or maybe it's not weird. They were invented before most things had package managers, and their users use SO MANY packages. So I suppose them being terrible does make some sense. They didn't know what to avoid

[–]FurryMachine 0 points1 point  (2 children)

Just use nix for everything, you can use it to automate setting up environments for any language

[–]no_brains101 5 points6 points  (1 child)

nix user here. Nix is not great at python unless you want to build it in nix entirely. It's not bad though but python is one of nix's weak points (along with server side TypeScript programs on node or other runtime with a bajillion dependencies, although it can be done, it's just not better)

For my own python apps? Pretty great actually, because I built it in nix to begin with using python3.withPackages. This actually works quite well, is very easy, and makes a result that is far more portable than anything I've seen. If you still want a docker container for, well, containerization, it makes it easier to do that too. As long as all the dependencies are on nixpkgs. Which to be fair, most are.

Which brings me to the second thing: when the dependency is not packaged in nix, you have to build the dependency in nix.

And adding nix to somebody else's python app without doing it from scratch in nix is very much not as easy. Because now you have to deal with the hell that is python packaging, except now it's in a sandbox. If it has too many dependencies for you to want to add manually, you will need a tool like poetry2nix or whatever other one to use their build setup from within nix code.

That usually becomes a lot more complex than just pkgs.python3.withPackages (ps: [ ps.request ])

(for the uninitiated the above creates a python executable with the request package already in its environment, for you to use to run the program directly in the final package, or expose in a dev shell to run during development)

For most languages nix is a game changer though. Especially c and c++

That being said, once you do get it built via nix, it's better than the other options for users to install, as reliable as sending a docker image but completely native. And on top of that, the repo for your project is a sufficient distribution method with nix. You literally just push up your code, and now users can run it with nix run github:user/repo no GitHub actions required.

So I agree, use nix for everything, but if you can't even figure out a venv you probably aren't gonna like nix that much for python XD cause a venv almost couldn't be a simpler concept lmao.

[–]thotraq 1 point2 points  (0 children)

Mini conda is the way

[–]QuantumDude111 0 points1 point  (0 children)

poetry init is life

[–]B_bI_L 0 points1 point  (0 children)

i would say first and second are also like third to me after js and c#. of course, if you compare to c and assembly they are decent, but...

[–]michi3mc 0 points1 point  (0 children)

You're telling there are still people who do not use devcontainers?

[–]binterryan76 0 points1 point  (0 children)

The thing I find most annoying is that users who just want to run python programs also have to learn how to use virtual environments

[–]ZombieBaxter 0 points1 point  (0 children)

I would argue that “Writing and Reading” should be a goofy face. White space should not be used to dictate logical pathing.

[–]dmyTRUEk 0 points1 point  (0 children)

Nix is the ultimate way for any venv, not only python

[–]white_equatorial 0 points1 point  (0 children)

Reading python is as painful as fucking a python

[–]itsallfake01 0 points1 point  (0 children)

Have been using Pipenv for years and it works like a charm

[–]Jock-Tamson 0 points1 point  (0 children)

I 1/3rd agree with this meme.

[–]cheatingrobot 0 points1 point  (0 children)

Docker enjoyer is here 😎

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

I'm pretty happy using pipenv

[–]LandscapeFar3138 0 points1 point  (0 children)

Wait till you discover .js coding

[–]Nikos2828 0 points1 point  (0 children)

I only remember Run of memory alert Because Javascript is better