-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunApp.py
32 lines (24 loc) · 977 Bytes
/
runApp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import sys
def activate_environment(env_name):
activate_script = os.path.join(env_name, 'Scripts', 'activate')
activate_command = f'call {activate_script}' if os.name == 'nt' else f'source {activate_script}'
try:
os.system(activate_command)
print(f'Activated virtual environment: {env_name}')
# Change this to your preferred server file
flask_app_name = "server_flask"
os.environ['FLASK_APP'] = flask_app_name
print(f'Set FLASK_APP to: {flask_app_name}')
# Run 'flask run' command
run_command = 'flask run'
os.system(run_command)
except Exception as e:
print(f'Error activating virtual environment: {env_name}')
print(f'Error message: {e}')
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: python activate_env.py <environment_name>')
sys.exit(1)
env_name = sys.argv[1]
activate_environment(env_name)