10

After having installed a new virtualenv, for example called ENV, if I type

. /path/to/ENV/bin/activate python import os print os.environ['VIRTUAL_ENV'] 

Then I see the /path/to/ENV/

However, if I type

/path/to/ENV/bin/python 

And then

import os print os.environ['VIRTUAL_ENV'] 

I've got a key error So what is the fundamental difference between these two methods? Thanks,

1 Answer 1

13

Inside the script at bin/activate, there's a line that looks like this:

VIRTUAL_ENV="/Users/me/.envs/myenv" export VIRTUAL_ENV 

Which is what's responsible for setting your VIRTUAL_ENV environment variable. When you don't use activate, that variable never gets exported - so it's not present in os.environ.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.