Due to a specific problem which I managed to solve, I spent most of today figuring out how site.py(s) work. There is a point which I don\'t understand.
As far as I u
The lib/python2.7/site-packages/site.py
file is not normally loaded. That's because it is lib/python2.7/site.py
's job to add the site-packages
paths to sys.path
to begin with, and the site.py
in site-packages
is simply not visible. If you have a site.py
in site-packages
then that is an error, there should be no such file there.
What happens in an unpatched Python without is:
sys.path
. site-packages
is not part of this list, unless you set a PYTHONPATH
variable that includes it anyway.site.py
, it'll import the one listed first on sys.path
.lib/python2.7/site.py
is found and loadedsite.py
adds site-packages
to sys.path
That's it, no further site.py
modules are loaded. Even if you tried, it'd find the module that was already imported; sys.modules['site']
exists and holds objects loaded from lib/python2.7/site.py
.
Your installation, however, has an older setuptools
installed, and it includes a special version of site.py, which the easy_install
command will install into site-packages if not yet present. It'll load the original site.py
by explicitly scanning the original sys.path
with any PYTHONPATH
-supplied paths ignored and loading the original site.py module manually using the imp.find_module() and imp.load_module() low-level functions, thus bypassing the normal module cache.
Its intent was to alter the sys.path
order to give PYTHONPATH
-listed .pth
files a higher precedence, see the original commit adding the patch:
Note: this version includes a hacked 'site.py' to support processing .pth files in directories that come before site-packages on sys.path.
The patch has been removed entirely from more recent setuptools
releases, as early as 2006 in the original setuptools.
So, either your Linux distribution has been set up to add lib/python2.7/site-packages
to your PYTHONPATH
or your shell has this set up for you, or your Python has been patched to include it, and you have the old setuptools
'patch' in your site-packages
.
It is entirely safe to remove that file.