@@ -162,8 +162,13 @@ export CUDA_HOME=/usr/local/cuda-${CUDA_VERSION}
162162export PATH="${CUDA_HOME}/bin:$PATH"
163163export CUDA_INCLUDE_DIRS=$CUDA_HOME/include
164164export CUDA_CUDART_LIBRARY=$CUDA_HOME/lib64/libcudart.so
165- export LD_LIBRARY_PATH=${CONDA_PREFIX}/lib:/usr/local/cuda-12.9/compat:${LD_LIBRARY_PATH:-}
166- export LIBRARY_PATH=${CUDA_HOME}/lib64:${LIBRARY_PATH:-}
165+
166+ # Add only CUDA compat libs to LD_LIBRARY_PATH (safe for system tools)
167+ if [ -n "${LD_LIBRARY_PATH:-}" ]; then
168+ export LD_LIBRARY_PATH="/usr/local/cuda-${CUDA_VERSION}/compat:${LD_LIBRARY_PATH}"
169+ else
170+ export LD_LIBRARY_PATH="/usr/local/cuda-${CUDA_VERSION}/compat"
171+ fi
167172EOF
168173
169174 # Create deactivation script to clean up
@@ -175,12 +180,41 @@ unset CUDA_NVCC_EXECUTABLE
175180unset CUDA_HOME
176181unset CUDA_INCLUDE_DIRS
177182unset CUDA_CUDART_LIBRARY
178- # Note: We don't unset PATH and LD_LIBRARY_PATH as they may have other content
183+ # We intentionally do not mutate PATH or LD_LIBRARY_PATH here.
184+ EOF
185+
186+ # #########################################
187+ # 2) Python-only LD_LIBRARY_PATH shim(s) #
188+ # #########################################
189+ # These shell *functions* ensure that any `python`/`python3` invocation
190+ # gets ${CONDA_PREFIX}/lib in its environment, without polluting the shell.
191+ # This avoids OpenSSL/libcrypto collisions with system tools like /usr/bin/conda.
192+ # TODO: Build Monarch with ABI3 to avoid this hack.
193+ local py_shim_activate=" ${conda_env_dir} /etc/conda/activate.d/python_ld_shim.sh"
194+ cat > " $py_shim_activate " << 'EOF '
195+ # Define python wrappers that only set LD_LIBRARY_PATH for the launched process
196+ python() { LD_LIBRARY_PATH="${CONDA_PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" command python "$@"; }
197+ python3() { LD_LIBRARY_PATH="${CONDA_PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" command python3 "$@"; }
198+
199+ # Export functions to subshells when possible (best-effort, shell-dependent)
200+ if [ -n "${BASH_VERSION:-}" ]; then
201+ export -f python python3 2>/dev/null || true
202+ elif [ -n "${ZSH_VERSION:-}" ]; then
203+ typeset -fx python python3 >/dev/null 2>&1 || true
204+ fi
179205EOF
180206
181- # Source the activation script so it works in the current session.
182- log_info " Loading CUDA environment for current session..."
207+ # Deactivation script to remove the function wrappers
208+ cat > " ${conda_env_dir} /etc/conda/deactivate.d/python_ld_shim.sh" << 'EOF '
209+ unset -f python 2>/dev/null || true
210+ unset -f python3 2>/dev/null || true
211+ EOF
212+
213+ log_info " Loading CUDA env and python LD shim for current session..."
214+ # shellcheck source=/dev/null
183215 source " $cuda_activation_script "
216+ # shellcheck source=/dev/null
217+ source " $py_shim_activate "
184218
185219 # Test installation
186220 log_info " Testing installation..."
197231
198232 echo " "
199233 log_info " Installation completed successfully!"
234+ echo " "
235+ log_info " Re-activate the conda environment to make the changes take effect:"
236+ log_info " conda activate $CONDA_DEFAULT_ENV "
200237}
201238
202239main " $@ "
0 commit comments