2đź‘Ť
âś…
Problem is when you source a bash file, it doesn’t really launch a new shell, but rather executes in the current shell, which is how it can actually change environment variables there. Your os.system('source ' + ve_path + 'bin/activate')
indeed launches a new bash and the changed environment variables disappear when that shell terminates.
At least on my system virtualenv generates a activate_this.py
file too. line two in that file explains how to use it. It’s an python version of the activate bash code.
Try putting this in your code instead of the source line: (oh well, I called my environment “A”, but I bet you got the idea now)
activate_this = 'A/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
👤mogul
Source:stackexchange.com