Skip to content

Instantly share code, notes, and snippets.

@mphuie
Created February 21, 2019 16:43
Show Gist options
  • Save mphuie/948fb99a4485274476b06ff5b6c7544a to your computer and use it in GitHub Desktop.
Save mphuie/948fb99a4485274476b06ff5b6c7544a to your computer and use it in GitHub Desktop.
python activate virtualenv in script
#!/usr/bin/env python3
import platform
from os import getcwd
def main():
from app import app
app.run(debug=True)
if __name__ == "__main__":
venv_platforms = ['Linux', 'Darwin']
running_os = platform.system()
# activate Linux/Darwin venvs:
if any(p in running_os for p in venv_platforms):
print("activated linux venv")
activate_this_file = "{}/venv/bin/activate_this.py".format(getcwd())
exec(open(activate_this_file).read(), dict(__file__=activate_this_file))
elif running_os == 'Windows':
print("Activating Windows venv")
activate_this_file = "{}\\winvenv\\Scripts\\activate_this.py".format(getcwd())
exec(open(activate_this_file).read(), dict(__file__=activate_this_file))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment