From b1b3bb6923400acd695bf255d8dc1e4cebfcdede Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Thu, 25 May 2023 09:15:05 -0500 Subject: [PATCH] Improve environment isolation (#68) --- cmd_linux.sh | 7 +++++++ cmd_macos.sh | 7 +++++++ cmd_windows.bat | 7 +++++++ start_linux.sh | 7 +++++++ start_macos.sh | 7 +++++++ start_windows.bat | 7 +++++++ update_linux.sh | 7 +++++++ update_macos.sh | 7 +++++++ update_windows.bat | 7 +++++++ 9 files changed, 63 insertions(+) diff --git a/cmd_linux.sh b/cmd_linux.sh index 08717db5..0a4ef620 100644 --- a/cmd_linux.sh +++ b/cmd_linux.sh @@ -8,5 +8,12 @@ if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can no CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" INSTALL_ENV_DIR="$(pwd)/installer_files/env" +# environment isolation +export PYTHONNOUSERSITE=1 +unset PYTHONPATH +unset PYTHONHOME +export CUDA_PATH="$INSTALL_ENV_DIR" +export CUDA_HOME="$CUDA_PATH" + # activate env bash --init-file <(echo "source \"$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh\" && conda activate \"$INSTALL_ENV_DIR\"") diff --git a/cmd_macos.sh b/cmd_macos.sh index 08717db5..0a4ef620 100644 --- a/cmd_macos.sh +++ b/cmd_macos.sh @@ -8,5 +8,12 @@ if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can no CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" INSTALL_ENV_DIR="$(pwd)/installer_files/env" +# environment isolation +export PYTHONNOUSERSITE=1 +unset PYTHONPATH +unset PYTHONHOME +export CUDA_PATH="$INSTALL_ENV_DIR" +export CUDA_HOME="$CUDA_PATH" + # activate env bash --init-file <(echo "source \"$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh\" && conda activate \"$INSTALL_ENV_DIR\"") diff --git a/cmd_windows.bat b/cmd_windows.bat index 4a5f4f0e..606ff485 100644 --- a/cmd_windows.bat +++ b/cmd_windows.bat @@ -14,6 +14,13 @@ set TEMP=%cd%\installer_files set CONDA_ROOT_PREFIX=%cd%\installer_files\conda set INSTALL_ENV_DIR=%cd%\installer_files\env +@rem environment isolation +set PYTHONNOUSERSITE=1 +set PYTHONPATH= +set PYTHONHOME= +set "CUDA_PATH=%INSTALL_ENV_DIR%" +set "CUDA_HOME=%CUDA_PATH%" + @rem activate installer env call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end ) diff --git a/start_linux.sh b/start_linux.sh index 5359179c..89d00c1c 100644 --- a/start_linux.sh +++ b/start_linux.sh @@ -49,6 +49,13 @@ if [ ! -e "$INSTALL_ENV_DIR/bin/python" ]; then exit fi +# environment isolation +export PYTHONNOUSERSITE=1 +unset PYTHONPATH +unset PYTHONHOME +export CUDA_PATH="$INSTALL_ENV_DIR" +export CUDA_HOME="$CUDA_PATH" + # activate installer env source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains about 'shell not initialized' (needed when running in a script) conda activate "$INSTALL_ENV_DIR" diff --git a/start_macos.sh b/start_macos.sh index 5686ce22..04ab07db 100644 --- a/start_macos.sh +++ b/start_macos.sh @@ -49,6 +49,13 @@ if [ ! -e "$INSTALL_ENV_DIR/bin/python" ]; then exit fi +# environment isolation +export PYTHONNOUSERSITE=1 +unset PYTHONPATH +unset PYTHONHOME +export CUDA_PATH="$INSTALL_ENV_DIR" +export CUDA_HOME="$CUDA_PATH" + # activate installer env source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains about 'shell not initialized' (needed when running in a script) conda activate "$INSTALL_ENV_DIR" diff --git a/start_windows.bat b/start_windows.bat index 9af086e6..063942fe 100644 --- a/start_windows.bat +++ b/start_windows.bat @@ -46,6 +46,13 @@ if not exist "%INSTALL_ENV_DIR%" ( @rem check if conda environment was actually created if not exist "%INSTALL_ENV_DIR%\python.exe" ( echo. && echo Conda environment is empty. && goto end ) +@rem environment isolation +set PYTHONNOUSERSITE=1 +set PYTHONPATH= +set PYTHONHOME= +set "CUDA_PATH=%INSTALL_ENV_DIR%" +set "CUDA_HOME=%CUDA_PATH%" + @rem activate installer env call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end ) diff --git a/update_linux.sh b/update_linux.sh index 5966f9d9..f7be8440 100644 --- a/update_linux.sh +++ b/update_linux.sh @@ -8,6 +8,13 @@ if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can no CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" INSTALL_ENV_DIR="$(pwd)/installer_files/env" +# environment isolation +export PYTHONNOUSERSITE=1 +unset PYTHONPATH +unset PYTHONHOME +export CUDA_PATH="$INSTALL_ENV_DIR" +export CUDA_HOME="$CUDA_PATH" + # activate installer env source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains about 'shell not initialized' (needed when running in a script) conda activate "$INSTALL_ENV_DIR" diff --git a/update_macos.sh b/update_macos.sh index 5966f9d9..f7be8440 100644 --- a/update_macos.sh +++ b/update_macos.sh @@ -8,6 +8,13 @@ if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can no CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" INSTALL_ENV_DIR="$(pwd)/installer_files/env" +# environment isolation +export PYTHONNOUSERSITE=1 +unset PYTHONPATH +unset PYTHONHOME +export CUDA_PATH="$INSTALL_ENV_DIR" +export CUDA_HOME="$CUDA_PATH" + # activate installer env source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains about 'shell not initialized' (needed when running in a script) conda activate "$INSTALL_ENV_DIR" diff --git a/update_windows.bat b/update_windows.bat index 4701ab48..a44e2188 100644 --- a/update_windows.bat +++ b/update_windows.bat @@ -14,6 +14,13 @@ set TEMP=%cd%\installer_files set CONDA_ROOT_PREFIX=%cd%\installer_files\conda set INSTALL_ENV_DIR=%cd%\installer_files\env +@rem environment isolation +set PYTHONNOUSERSITE=1 +set PYTHONPATH= +set PYTHONHOME= +set "CUDA_PATH=%INSTALL_ENV_DIR%" +set "CUDA_HOME=%CUDA_PATH%" + @rem activate installer env call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end )