site package does not work

Peter Otten __peter__ at web.de
Wed Jun 6 12:51:11 EDT 2018


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.

The function addusersitepackages() seems to be un(der)documented; looking at 
the source it turns out that the expected argument is a sequence of known 
paths rather than a directory you want to add.

If you need to add a directory that is not deteced by getusersitepackages() 
you can do so with addsitedir(my_directory) or by modifying sys.path 
directly with sys.path.append(my_directory).

However, 

> site.addusersitepackages('/home/erik/.local/lib/python3.6/site-packages'))

I recommend that you install the required packages as root rather than trick 
root into executing user-modifiable code, or, even better, that you run the 
cron job as user "erik".





More information about the Python-list mailing list