2017-09-02 30 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"}) 
相關問題