forked from agentos-project/agentos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_requirements.py
81 lines (69 loc) · 2.74 KB
/
install_requirements.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import subprocess
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).parent.absolute()
EXAMPLE_AGENT_PATH = REPO_ROOT / "example_agents"
DEV_REQS_PATH = REPO_ROOT / "dev-requirements.txt"
RLLIB_REQS_PATH = EXAMPLE_AGENT_PATH / "rllib_agent" / "requirements.txt"
SB3_REQS_PATH = EXAMPLE_AGENT_PATH / "sb3_agent" / "requirements.txt"
ACME_DQN_REQS_PATH = EXAMPLE_AGENT_PATH / "acme_dqn" / "requirements.txt"
ACME_R2D2_REQS_PATH = EXAMPLE_AGENT_PATH / "acme_r2d2" / "requirements.txt"
WEB_REQS_PATH = REPO_ROOT / "web" / "requirements.txt"
def install_with_pip(pip): # install with given pip
subprocess.run([pip, "install", "-r", DEV_REQS_PATH])
if sys.platform == "linux":
# Get CPU-only version of torch in case CUDA is not proper configured
subprocess.run(
[
pip,
"install",
"-r",
RLLIB_REQS_PATH,
"-f",
"https://download.pytorch.org/whl/torch_stable.html",
]
)
subprocess.run([pip, "install", "-r", ACME_DQN_REQS_PATH])
subprocess.run([pip, "install", "-r", ACME_R2D2_REQS_PATH])
else:
subprocess.run([pip, "install", "-r", RLLIB_REQS_PATH])
subprocess.run([pip, "install", "-r", SB3_REQS_PATH])
subprocess.run([pip, "install", "-r", WEB_REQS_PATH])
subprocess.run([pip, "install", "-e", REPO_ROOT])
def install_requirements():
answer = "n"
if len(sys.argv) > 1 and sys.argv[1] == "-y":
print("-y passed; will not confirm installation")
answer = "y"
else:
msg = (
"This will install all dev requirements and example agent "
"Python requirements into the currently active virtualenv. "
"Continue [y/n]? "
)
answer = input(msg)
if answer.lower() not in ["y", "yes"]:
print("Aborting...")
sys.exit(0)
# check if pip is installed and valid
pip_installed = True
try:
subprocess.check_call(["pip", "--version"], stdout=subprocess.DEVNULL)
except (FileNotFoundError, subprocess.CalledProcessError):
pip_installed = False
if pip_installed:
install_with_pip("pip")
else: # if pip is not installed, try again with pip3 before failing
pip3_installed = True
try:
subprocess.check_call(
["pip3", "--version"], stdout=subprocess.DEVNULL
)
except (FileNotFoundError, subprocess.CalledProcessError):
pip3_installed = False
if pip3_installed: # if pip3 exists
install_with_pip("pip3")
if not (pip_installed) and not (pip3_installed):
print("No valid pip or pip3 found, aborting...")
if __name__ == "__main__":
install_requirements()