
Solving the venv headache with a small utility?
Python’s virtual environments (venvs) are great — until you actually try to use them. Every project has its own .venv , but the moment you move around your filesystem, you’re stuck manually running: source .venv/bin/activate …over and over, in every project, forever. WHY? The flaw is structural: using environment variables for activating the venv was a design error. The reason is that it's impossible for a program to modify the shell environmentit was launched from. You have to activate the venv in every window where you are. There is no way around that... Shells had already solved this problem decades ago with tools like git , which automatically discover the nearest repository by walking upward through parent directories. So why not do the same for Python? 🔍 venv : Find the nearest .venv automatically and activate it Drop this into your .zshrc or .bashrc : # venv: search upward for the nearest .venv directory and activate it venv () { # Start from the current working directory local
Continue reading on Dev.to Python
Opens in a new tab



