2017-09-02 120 views
0

virtualenv文档说,以激活从内部蟒蛇的环境中,使用从运行Python3会话中激活的virtualenv

activate_this = '/path/to/env/bin/activate_this.py' 
execfile(activate_this, dict(__file__=activate_this)) 

execfile在Python 3不存在如果我尝试使用exec(open("venv/bin/activate_this.py").read()),它抱怨

AssertionError: You must run this like execfile('path/to/activate_this.py', dict(__file__='path/to/activate_this.py')) 

这是有道理的,因为activate_this.py提到了__file__

如何从python 3中激活virtualenv?

回答

2

__file__在全局:

exec(open("venv/bin/activate_this.py").read(), {'__file__': "venv/bin/activate_this.py"}) 
相关问题