|
3 | 3 | import ctypes |
4 | 4 | import sys |
5 | 5 | from pathlib import Path |
6 | | -parentFolder = str(Path(__file__).parent.parent) |
7 | | -activate_path = parentFolder + '\\env\\Scripts\\activate_this.py' |
| 6 | + |
| 7 | +def search_activation_path(): |
| 8 | + for i in range(5): |
| 9 | + final_path = str(Path(__file__).parents[i]) + '\\env\\Scripts\\activate_this.py' |
| 10 | + if os.path.exists(final_path): |
| 11 | + return final_path |
| 12 | + return '' |
| 13 | + |
| 14 | +activate_path = search_activation_path() |
8 | 15 | if os.path.exists(activate_path): |
9 | 16 | exec(open(activate_path).read(), {'__file__': activate_path}) |
10 | 17 | print(f'Aivia virtual environment activated\nUsing python: {activate_path}') |
11 | 18 | else: |
12 | | - # Attempt to still run the script with main Aivia python interpreter |
13 | | - error_mess = f'Error: {activate_path} was not found.\nPlease run the \'FirstTimeSetup.py\' script in Aivia first.' |
14 | | - ans = ctypes.windll.user32.MessageBoxW(0, error_mess, 'Error', 1) |
15 | | - if ans == 2: |
16 | | - sys.exit(error_mess) |
17 | | - print('\n'.join(['#' * 40, error_mess, |
18 | | - 'Now trying to fallback on python environment specified in Aivia options > Advanced.', |
19 | | - '#' * 40])) |
| 19 | + error_mess = f'Error: {activate_path} was not found.\n\nPlease check that:\n' \ |
| 20 | + f' 1/ The \'FirstTimeSetup.py\' script was already run in Aivia,\n' \ |
| 21 | + f' 2/ The current python recipe is in one of the "\\PythonEnvForAivia\\" subfolders.' |
| 22 | + ctypes.windll.user32.MessageBoxW(0, error_mess, 'Error', 0) |
| 23 | + sys.exit(error_mess) |
20 | 24 | # --------------------------------------------------------------- |
21 | 25 |
|
22 | 26 | # import time |
@@ -126,3 +130,5 @@ def run(params): |
126 | 130 | 'TCount': '3', 'ZCount': '100'} |
127 | 131 |
|
128 | 132 | run(params) |
| 133 | + |
| 134 | +# v2.01: - New virtual env code for auto-activation |
0 commit comments