Created
February 21, 2019 16:43
-
-
Save mphuie/948fb99a4485274476b06ff5b6c7544a to your computer and use it in GitHub Desktop.
python activate virtualenv in script
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
#!/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