From 510fd65ca950f35b2b26940ba6588036563b3ef6 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Fri, 13 Sep 2024 13:15:41 +0100 Subject: [PATCH] Wrapper : Set `PYTHONNOUSERSITE=1` This removes a common cause of conflicts between Gaffer and Python modules the user has installed using the system Python. Users who know what they are doing and want to use those modules in Gaffer can set `PYTHONNOUSERSITE=0` before running Gaffer to get the prior behaviour. Confession : I have not tests the `gaffer.cmd` changes - I an relying on Windows CI and review to do that. --- Changes.md | 2 ++ bin/gaffer | 9 +++++++++ bin/gaffer.cmd | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/Changes.md b/Changes.md index 719dc828e23..8eca76454d5 100644 --- a/Changes.md +++ b/Changes.md @@ -57,6 +57,7 @@ Fixes - usdview : Added Windows support (#5599). - ContextTracker : Removed unnecessary reference increment/decrement from `isTracked()`, `context()` and `isEnabled()`. - Menu : Fixed bug causing a menu item's tooltip to not hide when moving the cursor to another menu item without a tooltip. +- Python : Fixed startup failures caused by conflicting Python modules in the user `site-packages` directory. API --- @@ -117,6 +118,7 @@ Breaking Changes - FreezeTransform : Constant primitive variables with point/vector interpretations are now also transformed (this is more correct, but it is a change in behaviour). - ImageGadget : Remove non-const variant of `getContext()`. - LazyMethod : `deferUntilPlaybackStops` now requires that the Widget has a `scriptNode()` method rather than a `context()` method. +- Python : Gaffer now disables the user site-packages directory by setting `PYTHONNOUSERSITE=1`. To revert to the previous behaviour, set `PYTHONNOUSERSITE=0` before launching Gaffer. Build ----- diff --git a/bin/gaffer b/bin/gaffer index ed8cadf83f8..6eb2e2608a0 100755 --- a/bin/gaffer +++ b/bin/gaffer @@ -170,6 +170,15 @@ fi prependToPath "$GAFFER_ROOT/python" PYTHONPATH +if [[ -z $PYTHONNOUSERSITE ]] ; then + # Prevent Python automatically adding a user-level `site-packages` + # directory to the `sys.path`. These frequently contain modules which + # conflict with our own. Users who know what they are doing can set + # `PYTHONNOUSERSITE=0` before running Gaffer if they want to use + # the user directory. + export PYTHONNOUSERSITE=1 +fi + # Stop Cortex from making all Python modules load with RTLD_GLOBAL. export IECORE_RTLD_GLOBAL=0 diff --git a/bin/gaffer.cmd b/bin/gaffer.cmd index 54c14048d11..02ee3d81956 100644 --- a/bin/gaffer.cmd +++ b/bin/gaffer.cmd @@ -48,6 +48,15 @@ set PYTHONHOME=%GAFFER_ROOT% call :prependToPath "%GAFFER_ROOT%\python" PYTHONPATH +if "%PYTHONNOUSERSITE%" EQU "" ( + REM Prevent Python automatically adding a user-level `site-packages` + REM directory to the `sys.path`. These frequently contain modules which + REM conflict with our own. Users who know what they are doing can set + REM `PYTHONNOUSERSITE=0` before running Gaffer if they want to use + REM the user directory. + set PYTHONNOUSERSITE=1 +) + call :prependToPath "%GAFFER_ROOT%\lib" PATH set QT_OPENGL=desktop