Skip to content

Commit

Permalink
Remove user site-package from PYTHONPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapiitao committed Feb 10, 2023
1 parent b958484 commit c1b225f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions etc/profile.d/rdo-profile.sh
Expand Up @@ -12,3 +12,9 @@ releng_scripts_path="/releng/scripts/new_release_scripts"
if [ -d "$releng_scripts_path" ]; then
export PATH="$releng_scripts_path:$PATH"
fi

# As toolbox mount the HOME directory, we have to tell
# Python to not add the user site-packages dir ($HOME/.local/lib)
# to sys.path in order to avoid interaction with host system.
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONNOUSERSITE
export PYTHONNOUSERSITE=1

3 comments on commit c1b225f

@amoralej
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with PYTHONNOUSERSITE=1 regular releng commands fail:

[root@823ec8403c4b /]# rdo_projects -h
Traceback (most recent call last):
File "/usr/local/bin/rdo_projects", line 6, in
from rdoutils.cmd.rdo_projects import main
ModuleNotFoundError: No module named 'rdoutils'

As pip installs under /usr/local which i guess it considers user site packages

@jcapiitao
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

PYTHONNOUSERSITE=0 python3 -c 'import sys ; print(sys.path)'
['', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/var/home/jcapitao/.local/lib/python3.11/site-packages', '/usr/local/lib64/python3.11/site-packages', '/usr/local/lib/python3.11/site-packages', '/usr/lib64/python3.11/site-packages', '/usr/lib/python3.11/site-packages']

and

[jcapitao@toolbox releng]$ PYTHONNOUSERSITE=1 python3 -c 'import sys ; print(sys.path)'
['', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/usr/lib64/python3.11/site-packages', '/usr/lib/python3.11/site-packages']

@jcapiitao
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amoralej I fixed it with 0462205

Please sign in to comment.