Pyvenv puts both Python 2 and Python 3 in the same environment. Shocked!

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Dec 20 23:06:42 EST 2016


On Wednesday 21 December 2016 13:37, Malik Rumi wrote:

> I just created a new venv using pyvenv from a 2.7 install. Now I am shocked
> to see that I can get both 2.7 and 3.4 in this same venv:

I'm not an expert on pyvenv, but my guess is this:

Would you expect a command like "ls" or "grep" to continue to work from inside 
a venv? I expect you would say Yes.

How about "perl"?

If your venv has shadowed python, using the venv instead of the system python, 
there's no reason to expect that python3 will be any different than the same 
command outside of the venv. It will just run the same executable found in the 
PATH as normal, just like (say) "perl" or "grep".

> I did not even know this was possible. Doesn’t that defeat the purpose? More
> to the point, how do I make sure I am using the right one? 

Run this command from the shell prompt:

    which python

and that should tell you which executable you are getting.

(I think that should work inside a venv.)


> If I want the
> interpreter, that’s easy. But what happens when I want to install and use a
> program like Django? How do I control which interpreter Django uses? I’ve
> been through the official docs a couple of times today, but detailed
> explanations of pyvenv, let alone this dual version feature, have not been
> found. If you can point me to a good one, please do. Meanwhile...

How do you control which interpreter Django uses outside of a venv?




-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson




More information about the Python-list mailing list