forked from geometric-intelligence/neurometry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_environment.py
56 lines (43 loc) · 1.64 KB
/
setup_environment.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
import os
import subprocess
import sys
def is_cuda_available():
"""Check if CUDA is available on the system."""
try:
subprocess.run(
["nvidia-smi"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
return True
except Exception:
return False
def create_conda_environment(env_file_path):
"""Create a Conda environment from a yml file."""
try:
subprocess.run(["conda", "env", "create", "-f", env_file_path], check=True)
print("Conda environment created successfully.")
except subprocess.CalledProcessError as e:
print("Failed to create Conda environment:", e)
sys.exit(1)
def install_cuda_packages(env_name):
"""Install CUDA-dependent packages in the specified Conda environment."""
cuda_packages = ["cupy-cuda11x"]
for package in cuda_packages:
cmd = f"conda run -n {env_name} pip install {package}"
try:
subprocess.run(cmd, check=True, shell=True)
print(f"Installed {package} in {env_name} environment.")
except subprocess.CalledProcessError as e:
print(f"Failed to install {package} in {env_name}: {e}")
sys.exit(1)
def main():
env_file_path = "environment.yml"
# Create Conda environment
create_conda_environment(env_file_path)
# Check for CUDA availability and install packages if necessary
if is_cuda_available():
print("CUDA is available. Installing CUDA-dependent packages.")
install_cuda_packages("neurometry")
else:
print("CUDA not available. Skipping CUDA-dependent packages.")
if __name__ == "__main__":
main()