Last active
August 29, 2015 14:21
-
-
Save hjwp/0d29ec23940438a2d5e3 to your computer and use it in GitHub Desktop.
Load environment variables from bash into current python process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
script = '/home/harry/.virtualenvs/my-project-name/bin/postactivate' # eg | |
env_to_json = 'import os, json; print(json.dumps(dict(os.environ)))' | |
environ_json = subprocess.check_output( | |
'. {} && python -c "{}"'.format(script, env_to_json), | |
shell=True, env={} | |
) | |
os.environ.update(json.loads(environ_json.decode('utf8'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment