Skip to content

Commit f11e763

Browse files
authored
Adding virtual environment auto-activation
1 parent ab5d72f commit f11e763

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Recipes/RGBtoLuminance.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# -------- Activate virtual environment -------------------------
2+
import os
3+
import ctypes
4+
import sys
5+
from pathlib import Path
6+
parentFolder = str(Path(__file__).parent.parent)
7+
activate_path = parentFolder + '\\env\\Scripts\\activate_this.py'
8+
if os.path.exists(activate_path):
9+
exec(open(activate_path).read(), {'__file__': activate_path})
10+
print(f'Aivia virtual environment activated\nUsing python: {activate_path}')
11+
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]))
20+
# ---------------------------------------------------------------
21+
122
import os.path
223
import numpy as np
324
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)