Skip to content

Commit 97181da

Browse files
committed
Fix: Check if tmidas-env exists before creating to prevent installation failures
- Added environment existence check before attempting to create tmidas-env - Prevents script from failing when environment already exists (e.g., during cron job updates) - Ensures numpy and other dependencies are installed/updated on subsequent runs - Resolves missing numpy issue reported by users
1 parent d45651f commit 97181da

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

scripts/install_dependencies.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,23 @@ def prompt_install_jdk():
6868
print("Initializing conda...")
6969
run_command(f"{conda_executable} init bash")
7070

71-
# Create the environment
72-
print(f"Creating environment {env_name}...")
73-
run_command(f"{conda_executable} create -n {env_name} python=3.9 -y")
74-
75-
# Get the path to the created environment
76-
env_path = run_command(f"{conda_executable} env list --json").strip()
77-
env_path = json.loads(env_path)['envs']
78-
env_path = [path for path in env_path if path.endswith(env_name)][0]
71+
# Check if environment already exists
72+
env_list = run_command(f"{conda_executable} env list --json").strip()
73+
existing_envs = json.loads(env_list)['envs']
74+
env_exists = any(path.endswith(env_name) for path in existing_envs)
75+
76+
if env_exists:
77+
print(f"Environment {env_name} already exists. Updating packages...")
78+
env_path = [path for path in existing_envs if path.endswith(env_name)][0]
79+
else:
80+
# Create the environment
81+
print(f"Creating environment {env_name}...")
82+
run_command(f"{conda_executable} create -n {env_name} python=3.9 -y")
83+
84+
# Get the path to the created environment
85+
env_path = run_command(f"{conda_executable} env list --json").strip()
86+
env_path = json.loads(env_path)['envs']
87+
env_path = [path for path in env_path if path.endswith(env_name)][0]
7988

8089
# Set up the command prefix to run in the activated environment
8190
cmd_prefix = f"{conda_executable} run -n {env_name} "

0 commit comments

Comments
 (0)