bpo-36891: Enhancement in site.py by vx1920 · Pull Request #13246 · python/cpython
Allow "sitevendor" customization plugin in addition to "sitecustomize" and "usercustomuze".
I propose Anaconda to be shipped with proper startup/init code in PythonHome\sitevendor.py instead of using PythonHome\Scripts\activate.bat. Old sitecustomize and usercustomize plugins continue to work as before.
New "sitevendor.py" can be placed near python.exe and contain something like this:
# -----------------------------------
# Python-3
# sitecustomise.py/usercustomize.py: place in on PythonPath (e.g. near Python.exe)
# to enable additional startup configuration
# If found: it is called from PythonHome\Lib\site.py using "import XXXcustomize"
# See main() and exec_imp_module() in Lib\site.py
# -----------------------------------
import os
import sys
import site
from os.path import join, pathsep
prefix = os.path.split(os.path.abspath(sys.executable))[0]
####print("sitecustomize.py: prefix=" , prefix);
new_paths = pathsep.join([
prefix,
join(prefix, "Library", "mingw-w64", "bin"),
join(prefix, "Library", "usr", "bin"),
join(prefix, "Library", "bin"),
join(prefix, "Scripts")
])
L = [] # empty array for folders from path
env = os.environ
strpath = new_paths + pathsep + env['PATH'];
# string with combined path to array of folders:
for dir in strpath.split(';') :
L.append(dir);
####print("dir=%s" % (dir))
# remove duplicated and nonexested folders
site.removeduppaths_ex(L , True)
strpath = pathsep.join(L);
### modify environment variables for current process
env['PATH'] = strpath;
env['CONDA_PREFIX'] = prefix
# Python module search path:
site.removeduppaths_ex(sys.path , True) # True to remove nonexistent folder/files
# eof