Skip to content

Commit 63d1c35

Browse files
authored
Fix install script for all dependencies without breaking conda (Real!) (#121)
1 parent 3434e3f commit 63d1c35

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ python -m apps.grpo.main
2727

2828
If you need to re-build the wheels for whatever reason, you can do so with:
2929
```bash
30-
conda create -n forge python=3.10
31-
conda activate forge
3230
./scripts/build_wheels.sh
3331
```
3432

scripts/install.sh

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,13 @@ export CUDA_HOME=/usr/local/cuda-${CUDA_VERSION}
162162
export PATH="${CUDA_HOME}/bin:$PATH"
163163
export CUDA_INCLUDE_DIRS=$CUDA_HOME/include
164164
export 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
167172
EOF
168173

169174
# Create deactivation script to clean up
@@ -175,12 +180,41 @@ unset CUDA_NVCC_EXECUTABLE
175180
unset CUDA_HOME
176181
unset CUDA_INCLUDE_DIRS
177182
unset 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
179205
EOF
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..."
@@ -197,6 +231,9 @@ EOF
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

202239
main "$@"

0 commit comments

Comments
 (0)