Eryk Sun <eryk...@gmail.com> added the comment:
sys.prefix is usually argv0_path, but in a virtual environment argv0_path is set from "home" in pyvenv.cfg in order to find the standard library, and, if the site module is imported, sys.prefix is set to the virtual environment directory. Since for Windows site.getsitepackages() also includes sys.prefix, and since argv0_path and sys.prefix are different in this case, sys.path ends up with both of them. AFAIK, it needs neither of them. Adding argv0_path to sys.path is a vestige of the NT installation scheme in the 1990s. The old scheme had a "Bin" directory that contained "python.exe" and I presume the Python DLL and standard-library extension modules. The old setup.py installer [1] had the following code to set the value of the "PythonPath" registry key: path = [] pwd = nt.getcwd() for i in ["Bin", "Lib", "Lib\\win", "Lib\\tkinter", "Lib\\test", "Lib\\dos_8x3"]: i = pwd + "\\" + i path.append(i) sys.path[1:] = path pathvalue = strop.join(path, ";") #print "Setting PythonPath to", pathvalue win32api.RegSetValue(corehandle, "PythonPath", win32con.REG_SZ, pathvalue) Note the presence of the "Bin" directory in the list. Early NT releases used PC/getpath_nt.c [2], which was inconsistent with Modules/getpath.c in several ways. PC/getpathp.c was added in 1997. Early on, code was added to PC/getpathp.c to include the application directory in sys.path [3] in order to "make it work on NT". This was before it supported the registry "PythonPath" value that would have included the "Bin" directory. [1] https://github.com/python/cpython/blob/8f1b6519803ffa7aef45beb58bda654533cb1fa8/PC/setup_nt/setup.py [2] https://github.com/python/cpython/blob/8f1b6519803ffa7aef45beb58bda654533cb1fa8/PC/getpath_nt.c [3] https://github.com/python/cpython/commit/8f1b6519803ffa7aef45beb58bda654533cb1fa8 ---------- nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37089> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com