1

The Yosemite (OS X 10.10) upgrade includes Python 2.7.6, and the process, as usual with Apple system updates, seems to completely replace the system packages directory, in

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

This time, the process appears to have entirely omitted site.py. My understanding was that this file was essential to the functioning of Python, in particular, the proper construction of package search paths; but my Python (which uses nothing more than the Apple system Python and additional packages in site-packages) works fine, and my paths remain as they were before the upgrade.

Is site.py no longer needed for proper functioning of Python? Has it been moved to another location?

Community
  • 1
  • 1
orome
  • 45,163
  • 57
  • 202
  • 418
  • Do you have a site-packages and site-python folder? I assume you have done a search for the file as well? – RattleyCooper Oct 19 '14 at 15:20
  • @DuckPuncher: I have a site-packages folder (where I install all my packages): no site.py there. Where would I find "site-python"? – orome Oct 19 '14 at 15:23
  • I'm reading from [here](https://docs.python.org/2/library/site.html). It looks like when python initializes, site.py appends those folders to `sys.path` along with other folders? Unless I'm reading it incorrectly, it sounds like if `sys.path` contains the paths to those folders it means that `site.py` is running when a program is initialized. – RattleyCooper Oct 19 '14 at 15:29
  • @DuckPuncher: But that still seems to require a `site.py` (somewhere), which I can no longer find. (Using the [`-S` option](https://docs.python.org/2/library/site.html) omits my home directory and my `site-packages`, so the "automatic import" makes a difference; which implies that *something* is being imported.) – orome Oct 19 '14 at 15:40
  • Don't use the `-S` option. If you import `sys` and run `sys.path`, does the path to the `site-packages` folder show up? – RattleyCooper Oct 19 '14 at 15:44
  • @DuckPuncher: Yes. (For reference, with `-S` it does not). – orome Oct 19 '14 at 15:45
  • @raxacoricofalapatorius, Ok, because in the documentation on `site.py` it looks like `site.py` is run when a program initializes, it adds the path to the `site-packages` folder to `sys.path`, so it sounds like `site.py` exists somewhere. As far as finding it, that is something I can't help with. But if python works as it did before and your paths aren't affected, then it's probably safe to assume `site.py` exists. Especially if using the `-S` option omits those filepaths from `sys.path` since that is the expected behaviour. – RattleyCooper Oct 19 '14 at 15:50
  • @DuckPuncher: Agreed. I wonder where it is (I have no `site-python` folder that I can see.) – orome Oct 19 '14 at 16:00
  • I don't see one in my `sys.path` either. That might be for older versions of python. I have never heard of it before looking at the `site.py` docs. – RattleyCooper Oct 19 '14 at 16:02
  • @DuckPuncher: Must be. Still mystified why it all works (but at least it does!). Weirdly, using `python -m` reveals that neither [`USER_BASE`](https://docs.python.org/2/library/site.html#site.USER_BASE) nor [`USER_SITE`](https://docs.python.org/2/library/site.html#site.USER_SITE) exist, yet still it all works (or appears to). – orome Oct 19 '14 at 18:44

2 Answers2

2

site.py is still used. You are just not looking in the right location:

>>> import site
>>> print site.__file__
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc

The /Extras structure appears to consist entirely of non-standard-library packages, e.g. packages that Apple installs for their own uses that are not included with standard Python.

If there was a site.py file there in previous OS X versions it was in all likelihood one installed by setuptools; with 10.10 comes setuptools 1.1.6, which has long since got rid of the hack embodied in that file.

Community
  • 1
  • 1
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Excellent! And that (I assume) I should never touch! – orome Oct 19 '14 at 19:10
  • And [a related follow-on about `USER_SITE`](http://stackoverflow.com/q/26454521/656912). – orome Oct 19 '14 at 19:40
  • And: I assume the `site.py` that was in '../Extras/lib/python' was old and/or unused (or at least un-necessary, since Apple got rid of it as part of the Yosemite update). Correct? – orome Oct 19 '14 at 20:34
  • 1
    @raxacoricofallapatorius: older versions of setuptools included a [very hacky `site.py` file](http://stackoverflow.com/questions/25715039/python-interplay-between-lib-site-packages-site-py-and-lib-site-py/26035458#26035458), that is no longer needed and no longer present in current `setuptools` versions. Since Apple now ships wih `setuptools` version 1.1.6 I strongly suspect that you saw the setuptools `site.py` file here. So no, if you saw a `site.py` file there it is no longer needed. – Martijn Pieters Oct 19 '14 at 20:36
1

If the behaviour of python hasn't changed and sys.path contains the path to your site-packages folder, you should be fine. If you use the interpreters -S option, the path to the site-packages folder won't show up in sys.path, so you can test it. I would recommend searching for the file on your system. If it doesn't show up, make sure you can see hidden files in case it's hidden for some reason.

site.py docs

edit: Resolved in comments, but wanted to provide an official answer.

RattleyCooper
  • 4,997
  • 5
  • 27
  • 43