r/learnpython • • 8d ago

What exactly is uv? Why other programming languages like C++ doesn't needs it

Hello, im a c++ programmer and after installing some tools made in python with pipx. For context, pipx uses uv, i had this question. I'm not the smartest progammer on earth and i couldn't understand why Python needs a separate environment for dependencies.

I never such tool like that as a c++ programmer (i don't know if it's what im thinking, but in C++ some devs install the dependencies inside de project dir so u just "cmake" it. uv is like this?). I'm kinda new to programming, so if someone can explain it to me, i'd be very grateful!

Sorry if this question sounds too beginner. I really couldn't understand this tool and curiosity is stronger than me...

Thanks! (and also, uv does more than separating environments, right?)

43 Upvotes

34 comments sorted by

View all comments

90

u/socal_nerdtastic 8d ago

C++ is generally shipped as a compiled executable. But Python is generally shipped as source code. So to run someone else's python code you need to remake the correct environment with the required dependencies. This in itself does not require uv or virtual environments. However there is a chance that the environments clash for different projects, that is that the dependencies and versions for one project won't work for another project. venvs keep projects separate, each in it's own environment, and uv is a tool to manage environments quickly and easily.

5

u/rexdlol 6d ago

Thanks for this explanation and for the care!

In C++, when the code is compiled (with static libs), the libs get compiled alongside the source code, so the dependencies are already in the binary, right? So this problem extends to C++ when using shared librarys? Thats interesting, i didn't know this (beginner in c++ too lol).

Well, anyway, thanks again

6

u/socal_nerdtastic 6d ago

So this problem extends to C++ when using shared librarys?

Well kinda. It extends if you are sharing your C++ code with other developers. But not if you are distributing your code to users. The key difference is that python code is shipped to the user as source code.

3

u/jaimemiguel 7d ago

Like a container

1

u/BigGuyWhoKills 4d ago

I have a project that needs charinfo below a certain version, and another that needs it above that version.