Virtualenv bin/activate isn't doing anything "wrong". It's just not doing it how the author believes is best. Can the whole "You're doing X wrong" meme die already please?<p>I like the idea though! From what I see so far the author makes a good argument for using a subshell rather than setting and resetting environment variables. At the same time though, I haven't enough experience with his suggestion yet to see the downsides... and there most definitely will be. Why? Because that's programming, man. There's no panacea, no perfect way to do things, no <i>true</i> "best" way to do anything.<p>So is this the "right" way? Probably not. Better is probably more like it and using that word instead makes you seem, you know, like <i>not</i> cocky asshole (not that I think that about the author at all, just generally speaking).
Venv is one of the pieces of sanity in the python packaging deployment world and any improvements welcome - this goes on my List if things to think hard about
I handle this issue (and a bunch of other environment variable issues) with a little utility I wrote.<p><a href="https://github.com/timtadh/swork" rel="nofollow">https://github.com/timtadh/swork</a><p>It basically figures out the pid of your shell and dumps the environment variables into a file in /tmp/swork. Then you make custom activate scripts for all of your projects. It has really helped me deal with a lot of projects. It also has convenience functions for quickly cd'ing to any project.<p>When you want to get back to the original configuration it simply restores the original environment vars.
The approach i use is simply:<p><pre><code> $ cat run
#!/bin/sh
. venv/bin/activate
python main.py
</code></pre>
Is this wrong? If so, what would work better?
None of these problems are the kinds of problems I've <i>ever</i> run into. They're entirely a series of what if and edge case scenarios in which virtualenv is <i>not</i> the answer, which is fine. I don't need a tool that can do things I'm never going to do.
This is also the same technique I like to use for providing configuration to applications. Basically, write YOUR_APP_ENV=prod or whatever into /etc/environment and then add appenv to PATH which tests against the machine's environment, sets all the appropriate environment variables accordingly and ends with an `exec`. Super nice way to provide shell-friendly language-agnostic configuration.<p>I used to use `exec env $@` at the end of the script, so that I could `appenv > prod` for diffing, but I actually prefer this articles suggestion: `exec "${@:-$SHELL}"` since you can still `appenv env > prod`, but `appenv` provides an interactive shell by default.
But what will be the added CO2 footprint of launching so many unnecessary shells!<p>Also, I don't like the prospect of having to hit Ctrl-D twice to logout.
This is also how all HPC computing environments (such as SLURM, SGE) do it. They simply spawn a subshell for you to work with and do whatever you want to run.