3 ms·
My convention for about the last ten years has been that every Python project I work on gets a `ve` directory where I install the virtualenv. Then `./ve/bin/pip
by thraxil 5y ago
My convention for about the last ten years has been that every Python project I work on gets a `ve` directory where I install the virtualenv. Then `./ve/bin/pip install -r requirements.txt` and `./ve/bin/python myscript` are just kind of hard-wired into my muscle memory. I do a lot of Django and on Django projects almost everything is done via `manage.py`, so I just change the shebang line in it to `#!ve/bin/python` and then I can do `./manage.py whatever` and it always works. I never have to remember to "activate" virtualenvs and I never accidently run a script with the wrong virtualenv activated. When I pair with other Python developers, I'm always amazed at how much time and focus they have to put into keeping track of that stuff and how much confusion it causes.
- tedmiston 5y agoThis comment made me wonder if there's a tool out there akin to ~~autoenv~~ direnv [1], but that automatically activates a virtual environment when you cd into a directory with e.g., a poetry.lock. Surprisingly, it seems like the answer today is no. But there's a little bash snippet that wraps cd to give us a start [2]. But just dropping `poetry shell` in an `.envrc` for direnv is better than nothing too. [1]: https://github.com/direnv/direnv https://github.com/direnv/direnv [2]: https://stackoverflow.com/a/50830617/149428 https://stackoverflow.com/a/50830617/149428