PYTHONSITEDIR environment variable

ago agostino.russo at gmail.com
Tue Sep 9 20:47:52 CEST 2008


Small variation on the above patch, using 2 environment variables:
PYTHONSITEDIR allows for local site-packages (that override system
site packages), and PYTHONNOSYSSITES skips system site-packages for
"clean-room" operation (similar to virtual-python.py --no-site-
packages).


--- /usr/lib/python2.5/site.py  2008-05-29 22:03:04.000000000 +0100
+++ /tmp/site.py        2008-09-09 19:56:44.000000000 +0100
@@ -167,6 +167,11 @@

 def addsitepackages(known_paths):
     """Add site-packages (and possibly site-python) to sys.path"""
+    sitedir = os.environ.get('PYTHONSITEDIR')
+    if sitedir and os.path.isdir(sitedir):
+        addsitedir(sitedir, known_paths)
+    if os.environ.get('PYTHONNOSYSSITES'):
+        return None
     prefixes = [sys.prefix]
     if sys.exec_prefix != sys.prefix:
         prefixes.append(sys.exec_prefix)





More information about the Python-list mailing list