I'm working on a mod_wsgi script.. at the beginning is:

sys.path.extend(map(os.path.abspath, ['/media/server/www/webroot/']))

But I've noticed, that every time I update the script the sys.path var keeps growing with duplicates of this extension:


It resets every time I restart apache.. is there any way to make sure this doesn't happen? I want the module path to be loaded only once..

Accepted Answer

No need to worry about checking or using abspath yourself. Use the ‘site’ module's built-in addsitedir function. It will take care of these issues and others (eg. pth files) automatically:

import site

(This function is only documented in Python 2.6, but it has pretty much always existed.)

Written by bobince
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki