[CentralOH] Care and feeding of Python Virtual Environments

cohpy at gregback.net cohpy at gregback.net
Sat Sep 5 13:20:25 EDT 2020


Hey Damien-

I mostly use virtualenvwrapper [0], which puts virtualenvs in one 
directory. (I've used it since before venv was a thing, but I think it 
uses venv under the hood now.) With the `workon` command, I don't really 
need to worry about where they are in order to activate them. It can be 
a bit of a hassle to get virtualenvwrapper installed into the right 
Python installation (it's a PyPI package) that doesn't break when you 
upgrade Python, especially with Homebrew. I think it's a lot nicer on 
Ubuntu where the virtualenvwrapper deb package is linked to the Python 
deb package.

I also use VS Code, which will automatically use a virtualenv if you 
specify it in the project config (settings.json). For shared projects, 
or really any project where I want to check settings.json into git, it's 
easier to use a location relative to the project root. If it's a project 
I'm collaborating with other VS Code users, I'll typically symlink the 
virtualenv directory into the project folder (like [1]), and add it to 
gitignore [2], so I can take advantage of virtualenvwrapper and the 
workon command without leaking paths or having to adapt the path to 
different machines/users.

I know there are tools that let you automatically activate a virtualenv 
when you're in certain directory, but those are personally too much 
magic for me.

Greg

[0] https://virtualenvwrapper.readthedocs.io/en/latest/
[1] https://github.com/gtback/ght/blob/main/.vscode/settings.json
[2] https://github.com/gtback/ght/blob/main/.gitignore#L133

On 2020-08-19 2:52 PM, Damien Calloway wrote:
> Hello !
>
> I use venv for my blog (which is generated from Nikola) and I also use 
> it for Sphinx, and want to know how everyone handles their virtual 
> environments. Right now, I have them set up in the project directory 
> of each project i am working on, but I heard that some people prefer 
> to put all their virtual environments in one spot.
>
> I am curious about which approach would work better, as I am a bit 
> annoyed at having to dive deep into the project folders in order to 
> hop into a venv, or switch from one task in one project to another 
> task in another project. Online searches for this kind of stuff has 
> too much voodoo superstition to be useful. Any ideas ?
>
> Thank you,
>
> Damien
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh



More information about the CentralOH mailing list