On 06/05/2018 01:33 PM, Erik Martinson via Python-list wrote:
I am trying to dynamically add a site-package to a script that is run as a cron
job. The method adduseristepackages does not seem to do anything.
import sys
import site
print('-------------------------')print(site.getusersitepackages())
print('add',
site.addusersitepackages('/home/erik/.local/lib/python3.6/site-packages'))
print(site.getusersitepackages())
print(site.getsitepackages())
print(site.check_enableusersite())
output:-------------------------
/root/.local/lib/python3.6/site-packages
add /home/erik/.local/lib/python3.6/site-packages
/root/.local/lib/python3.6/site-packages
['/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages',
'/usr/lib/python3.6/dist-packages']
True
Thanks,
Erik
It seems you are trying to run your script from the root cron job rather
than the user's cron job, and then trying to add a user site directory
to root's site path. From the docs:
|site.||ENABLE_USER_SITE|
Flag showing the status of the usersite-packages
directory.|True|means that it is enabled and was added
to|sys.path|.|False|means that it was disabled by user request
(with|-s|
<https://docs.python.org/3/using/cmdline.html#cmdoption-s>or|PYTHONNOUSERSITE|
<https://docs.python.org/3/using/cmdline.html#envvar-PYTHONNOUSERSITE>).|None|means
it was disabled for security reasons (mismatch between user or group
id and effective id) or by an administrator.
||
So perhaps a mismatch between UID/GID and EID is causing the whole
process to silently fail... ||
-Jim
||
--
https://mail.python.org/mailman/listinfo/python-list