Skip to content

Commit 27fffb3

Browse files
authored
Update ZColorCoding.py
1 parent befcace commit 27fffb3

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

Recipes/TransformImages/ZColorCoding.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
import ctypes
44
import sys
55
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()
815
if os.path.exists(activate_path):
916
exec(open(activate_path).read(), {'__file__': activate_path})
1017
print(f'Aivia virtual environment activated\nUsing python: {activate_path}')
1118
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)
2024
# ---------------------------------------------------------------
2125

2226
# import time
@@ -126,3 +130,5 @@ def run(params):
126130
'TCount': '3', 'ZCount': '100'}
127131

128132
run(params)
133+
134+
# v2.01: - New virtual env code for auto-activation

0 commit comments

Comments
 (0)