-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_install.py
More file actions
37 lines (31 loc) · 1.18 KB
/
user_install.py
File metadata and controls
37 lines (31 loc) · 1.18 KB
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
32
33
34
35
36
37
import os
import sys
import subprocess
import venv
env_dir = os.path.join(os.path.dirname(__file__), ".temp_env")
if os.name == "nt":
print("Installer is not compatible with Windows! Exiting...")
sys.exit()
else:
pip_path = os.path.join(env_dir, "bin", "pip")
python_path = os.path.join(env_dir, "bin", "python")
os.environ["PIP_CMD"] = f"{pip_path} install"
activate_scripts = [os.path.join(env_dir, "bin", "activate"), os.path.join(env_dir, "bin", "activate.csh")]
if not os.path.exists(python_path):
builder = venv.EnvBuilder(with_pip=True)
builder.create(env_dir)
packages = ["tqdm"]
try:
subprocess.check_call([pip_path, "install"] + packages)
except subprocess.CalledProcessError:
print(f"Unable to install {', '.join(packages)}. Please proceed manually.")
sys.exit()
shell = os.environ.get("SHELL", "bash")
for activate in activate_scripts:
try:
print([shell, "-c", f"'source {activate}'", "&&", "python3", "heainstaller.py"])
subprocess.run([shell, "-c", f"source {activate} && python3 heainstaller.py"], check=True )
break
except:
print(f"Unable to activate venv or run script. Exiting")
sys.exit()