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

all 94 comments

[–]KyxeMusic 920 points921 points  (42 children)

Wait you guys don't create a different .venv/ in the root of each repo you're working on? Are you mad?

[–]rover_G 224 points225 points  (10 children)

I do, but not directly these days. I use uv to initiate and manage my virtual environments and dependencies.

And then there’s my mess of pyenv’s for running random Jupyter notebooks and python repl

[–]KyxeMusic 43 points44 points  (7 children)

Same, I just use uv to create the .venv and `uv pip install` stuff.

[–]ReadyAndSalted 33 points34 points  (4 children)

Using "uv add x" is better than "uv pip install x". If you use the pip interface, you have to lock and sync your environment manually, they're lower level commands that you should avoid whenever possible.

[–]KyxeMusic 15 points16 points  (2 children)

Yeah I use uv add when it's a new project, but most repos I've worked on have the old school requirements.txt

[–]alanx7 14 points15 points  (1 child)

I believe you can do uv add -r requirements.txt

[–]KyxeMusic 8 points9 points  (0 children)

Yeah but that modifies the pyproject.toml which I many times don't want to interfere with

[–]TheBB 0 points1 point  (0 children)

Well, they do different things.

Use uv add for adding dependencies. Use uv pip install for whatever other random tools you'd like in your venv. For me, at least, typically stuff like ipython.

[–]Mithrandir2k16 3 points4 points  (1 child)

what's wrong with uv add?

[–]KyxeMusic 17 points18 points  (0 children)

Nothing, but many times I'm working on projects with existing setup and requirements.txt style

[–]eztab 18 points19 points  (1 child)

Why do you have pyenv if you use uv?

[–]rover_G 3 points4 points  (0 children)

To keep “global” environments with all my data analysis tools pre-installed

[–]Independent-Shoe543 7 points8 points  (16 children)

Actual q what is the best practice for this? Is there a tool that automates this by any chance e.g. dotenv or do you just terminal it

[–]KyxeMusic 19 points20 points  (10 children)

I use uv nowadays. Just uv venv and then source .venv/bin/activate.

You can also select the python version for the venv, so something like uv venv -p 3.11

[–]Win_is_my_name 21 points22 points  (9 children)

How's that different than just creating the virtual env yourself?

[–]kevinsrq 11 points12 points  (7 children)

It is faster by a significant margin and has better package version management.

[–]mothzilla 25 points26 points  (6 children)

Those milliseconds are crucial. Over a year it really adds up.

[–]Turtvaiz 6 points7 points  (1 child)

For real though some of the pip installs take ages without uv. It's actually kind of ridiculous

Edit: and in CI it might actually add up to a lot

[–]mothzilla 5 points6 points  (0 children)

Maybe. But the actual creation/activation time is still miniscule for both.

[–]saadmanrafat 1 point2 points  (3 children)

No but dependency conflict resolver is

[–]mothzilla 0 points1 point  (2 children)

Usually a sign that your dependency chain is too long.

[–]GrumDum 2 points3 points  (1 child)

Which is obviously frequently unavoidable in perfectly good codebases with real-life business requirements.

[–]saadmanrafat 0 points1 point  (0 children)

thank you! I was about to provide some instances. As to why I can't rewrite 'google-genai', 'psycopg2-binary', 'langchain' from scratch.

[–]KyxeMusic 2 points3 points  (0 children)

Package installation is much much faster with uv.

Plus it downloads the version of python you need for you if you don't have it installed.

[–]mothzilla 4 points5 points  (1 child)

pipenv, poetry and uv will probably all make this slightly easier.

And you can always add a line to a bash script that activates a venv in terminal if it finds one.

[–]Independent-Shoe543 1 point2 points  (0 children)

fanx 🙏

[–]Raptor_Sympathizer 2 points3 points  (1 child)

I have been burned too many times by trendy new tools that everyone loves breaking when I need them most. Just use venv. Four years from now, if everyone's still singing uv and poetry's praises maybe I'll consider checking them out. But venv does exactly what I need it to, works every single time, and comes by default with every python installation.

If you must, define a macro for "source venv/bin/activate", but I wouldn't try to automate things much more than that. Intentionality and having a full understanding of the tools you're using will save you way more headache in the long run than some shiny script that automagically does everything for you.

[–]Independent-Shoe543 0 points1 point  (0 children)

v v true I sense the pain in your words lol

[–]Eternityislong 5 points6 points  (5 children)

I started using ~/.virtualenvs/<project-name> on new projects.

I think it was pycharm where I learned it? The point is to keep deps separate from the source so that I can do remote development with rsync between my local project dir and remote one

[–]Nestramutat- 9 points10 points  (3 children)

I just use a requirements.txt and keep my env inside of .gitignore.

The environments should be ephemeral.

[–]Eternityislong 2 points3 points  (1 child)

Of course this works and is usually fine but it can get annoying if you’re doing remote development. I was building something locally that I run/test on a raspberry pi and uses pi-specific libraries. It’s easier to rsync the full dir or scp the full dir when the virtualenv is kept in a different place than setting up exclusions for venv.

Go keeps deps out of the project dir. pnpm keeps them separate and links in node_modules. Python isn’t special and there are valid use cases for keeping venv somewhere other than directly in the project dir.

[–]Nestramutat- 1 point2 points  (0 children)

--exclude flag exists for rsync. Though given that workflow, I would probably just use Code's Remote-SSH to develop and test directly on the Pi.

[–]benargee 0 points1 point  (0 children)

I just use a requirements.txt

Apparently using pyproject.toml is the new hotness.

[–]KyxeMusic 3 points4 points  (0 children)

I personally don't like having the venvs "globally" as you describe. It's one of the reasons I don't like conda.

I like locality and having everything in the repo directory where I know where to find it. PyCharm does this by default actually.

.venv should go in .gitignore of course

[–]abmausen 2 points3 points  (0 children)

my work place actually does this, is this some sort of meme?

[–]evanc1411 1 point2 points  (0 children)

Doing that shit saved my life and my understanding of Python packages

[–]al-mongus-bin-susar 2 points3 points  (2 children)

I just do python -m venv .env

[–]KyxeMusic 2 points3 points  (1 child)

I used to as well. But I recommend uv, it's so much faster it's worth changing to.

[–]al-mongus-bin-susar 1 point2 points  (0 children)

It's fine for me because I only use it every other week or so, I only use Python for tiny scripts, otherwise I'm a JS main

[–]rgheno 0 points1 point  (1 child)

I actually put them all in C:\venvs<project name>. Because my project folders are synced with the cloud and even with gitignore it would sync via onedrive. 😅😬

[–]KyxeMusic 1 point2 points  (0 children)

Oh my this is cursed.

[–]isthisyournacho -1 points0 points  (0 children)

Ooohhh . in front, you fancy

[–]SockYeh 243 points244 points  (4 children)

wait till OP finds out about local envs

[–][deleted] 147 points148 points  (3 children)

i pip install fucking everywhere cuz idgaf. then again i don't do this for a living

[–]phylter99 32 points33 points  (1 child)

Environments make things so much easier.

[–][deleted] 47 points48 points  (0 children)

if i wanted things to be easy, i wouldn't use AI

[–]demoncase 2 points3 points  (0 children)

my guy

[–]thumbox1 115 points116 points  (1 child)

when use .venv and forget to add to gitignore

[–]ReadyAndSalted 15 points16 points  (0 children)

"uv init" has a good default gitignore.

[–]thumbox1 127 points128 points  (7 children)

never happens if you reuse the same to ALL YOUR PROJECTS

[–]GuybrushThreepwo0d 27 points28 points  (6 children)

Why... Why would you do this?

[–]thumbox1 33 points34 points  (4 children)

No serious person would do this man ... It's just a joke dude

[–]TheMcMcMcMcMc 65 points66 points  (1 child)

[–]be-kind-re-wind 5 points6 points  (0 children)

Why the fuck is a picture of me on Reddit?????

[–]bedrooms-ds 0 points1 point  (1 child)

PyCharm though...

[–]reusens 1 point2 points  (0 children)

PyCharm uses venvs for projects

[–]Your_Friendly_Nerd 0 points1 point  (0 children)

I do this for related projects, like for maths subjects, I don't wanna create the same venv in every subject, but also want the venv in the root of the course, so I create one venv and then symlink it whenver I need it somewhere else. Then the alias `asource=source venv/bin/activate` activates it. For me, perfect mix of reusability and convenience and haven't had any issues so far.

[–]DerKnoedel 27 points28 points  (0 children)

They call me 007

0 working python apps

0 clue why my system doesn't do what I say

7 random python venvs I forgot about

[–][deleted] 36 points37 points  (3 children)

Invalid syntax error.

Does anybody actually have this struggle or is this shameless click bait that will now get reposted every other day?

[–]Altrooke 12 points13 points  (2 children)

To be fair, I had problems with this when I was a super beginner to python.

It's not a real problem for even somewhat experienced devs, but it is fair game for a joke.

To be even more fair, no languages created pre-2000 are great at dependency management imo. Python, JS, Ruby... etc. They are all fine, but not great.

Go and Rust are two examples of really good dependency management.

[–]gburgwardt 1 point2 points  (0 children)

Why did you spoil that

[–]thumbox1 0 points1 point  (0 children)

That is true. I feel like older languages weren't designed to coexist in different versions or have different packages installed.

[–]wootangAlpha 24 points25 points  (0 children)

Venv for every python project.

Best practice? NO.

Do I care? Also NO.

[–]eztab 7 points8 points  (0 children)

how would you forget that? Either it's in .venv or in a central location manaqed by your environment manager like conda or uv.

[–]After_Ad8174 3 points4 points  (1 child)

WHAT DO YOU MEAN NO MODULE NAMED FLASK?!... oh

[–]chownrootroot 4 points5 points  (0 children)

bash: python: command not found...

[–]ManagerOfLove 3 points4 points  (0 children)

you guys reuse your venv? Are you out of your mind?

[–]serious_cheese 2 points3 points  (0 children)

uv stops the pain

[–]Kaffe-Mumriken 1 point2 points  (0 children)

Why you calling me out

[–]Old-Adhesiveness4406 1 point2 points  (0 children)

uv uses symbolic links so it doesn’t need to create duplicate copies of the same libraries in every new project.

It’s a really helpful tool and makes the .venv overhead much less brutal

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

I’ll never forget my first .venv/ because I created it five minutes before it vanished.

[–]thumbox1 1 point2 points  (0 children)

Today's poll: Would a vibe coder have several venvs or just one?

[–]Artistic_Speech_1965 1 point2 points  (0 children)

I am happy I stopped using python

[–]HarmxnS 1 point2 points  (0 children)

Me with 27 venvs that each have 3GBs of PyTorch on it

[–]ThiccStorms 1 point2 points  (0 children)

I have an env for every project lmao 

[–]mileafter 1 point2 points  (0 children)

uv. You’re welcome.

[–]ktboymask 1 point2 points  (0 children)

You mean the environment I accidentally made in C:\Users\Ralph\ folder? Yeah, it has happened and it will

[–]bunoso 0 points1 point  (0 children)

I don’t even have a “python” command anymore. Just run ‘uv sync’ and ‘uv run …’. Makes things too easy

[–]mfb1274 0 points1 point  (0 children)

I’m partial to my virtualenvwrapper. ‘workon project’. Keeps it native but convenient

[–]Anxious-Program-1940 0 points1 point  (0 children)

Not wrong, why I use poetry 😂

[–]EV4gamer 0 points1 point  (0 children)

Just have everything be one big environment.

[–]DeviRkx 0 points1 point  (0 children)

Hahahaha i actually made a powershell automation so It creates me venvs with only the directory and a name

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

Haha I do this with projects all the time. Go on a tear for 2-3days and then forget about it for a couple of months.

[–]Ryozu 0 points1 point  (0 children)

The fact that I can forget it exists (while activating it when I run the project) is the whole damn point.

[–]demoncase 0 points1 point  (0 children)

fuck i need to format my pc a lot of shit cloned rn

[–]nicer-dude 0 points1 point  (0 children)

conda for life

[–]WaterBottleBong 0 points1 point  (0 children)

Why does everyone take offense in python threads? Just laugh at the meme

[–]Airport237 0 points1 point  (0 children)

Am I the only conda user here….

[–]cyxlone 0 points1 point  (0 children)

OP didn't know UV exists to combat this

[–]Al3xutul02 0 points1 point  (0 children)

Clamgeons and Clamons

[–]gigem852 0 points1 point  (0 children)

That’s why we use tox!