10

[tl;dr? see bottom]

Python on OS X has always been somewhat of an abomination in that it's split up and spread out all across the system. Some in /usr, some in /Library/Python, some /System/Library/Frameworks/Python.framework.

Now, as I understand it, the framework is supposed to contain the Python distribution, i.e. the bits and pieces that aren't going to change. An example would be headers, the standard library, the binary images, etc.

So as a developer of a sort-of-popular Python C extension, I think myself to be pretty good at the OS X ecosystem and how to compile Python extensions on it. It wasn't a month ago that Apple decided to skip on QA, breaking C extension building across the board.

It's broken in yet a new way though, as Apple seem to have decided to remove the better part of the Python distribution. Take a look at the include/ directory:

$ ls -l /System/Library/Frameworks/Python.framework/Versions/Current/include/python2.6 
total 16
-rw-r--r--  1 root  wheel    30K Jun 25  2010 pyconfig.h

Missing something? The Python.h header perhaps? What's more, I had woes with zc.buildout because it couldn't find site.py... Have a look-see:

$ python -c 'print __import__("site").__file__'
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.pyc

$ ls -l /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.py*
-rw-r--r--  1 root  wheel    20K May 17 15:40 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.pyc

Missing something? The site.py original perhaps?

All in all, it seems Apple are stripping out vital developer resources. I confirmed both of these findings on other MacBooks with OS X 10.6.7.

tl;dr Apple have removed lots of vital headers and source-code from the Python framework. Has this happened anybody else? If so, when did this happen? Why did it happen? And most importantly, how do I get them back?

5
  • 4
    You are usually better of to install a separate version of Python anyway (especially if you want to use numpy/scipy). May 27, 2011 at 11:32
  • Both look ok for me on my MacBook Pro and my MacPro both with 10.6.7
    – Asgeir
    May 27, 2011 at 11:34
  • But I know this used to work before! And it still does for @Asgeir
    – lericson
    May 29, 2011 at 11:45
  • I guess I should've thought of reinstall Xcode!
    – lericson
    May 30, 2011 at 15:32
  • I know this is old post but OS X Mavericks 10.9+ FYI Python.framework "SDK Python.framework is deprecated, and the standard *nix method of using the python.h header should be used instead." stackoverflow.com/a/19758680/1896134
    – JayRizzo
    Jun 7, 2022 at 1:50

3 Answers 3

6

Python.h and other headers are included with Xcode. On my system, it's located in both /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h and /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h. The latter appears to be installed by the Xcode installer.

1
  • So you still have one in /System/Library/Python.framework then. That's my problem, it seems. :-( Nobody knows why either?
    – lericson
    May 29, 2011 at 11:47
3

Actually, it doesn't look like you understand the OS X ecosystem at all. /System/Library is for Apple-shipped components of the OS X "distribution"; third parties must not put files in there, but should use /Library instead. That's why the built-in Pythons (multiple versions) are in /System/Library/Frameworks/Python.framework, but place the site-packages directories in /Library/Python, so that third-party modules can be installed there. As for /usr/bin, it contains symlinks to the python executable by version, and programs that autoselect the version based on some parameters (see man python). It's actually quite logical and tidy.

Now to answer your questions. C headers and other developer resources are not included in the default install of OS X. This is not specific to Python, and was done to save space on a default install. To get the developer resources, you need to install the developer tools. What were you going to do with a C header without a C compiler, anyway?

5
  • 1
    The tone of this answer is very poor; you seem to be looking for an argument. I said exactly what you said in your answer, you're reiterating the same information. Very unhelpful.
    – lericson
    May 29, 2011 at 11:44
  • 2
    What a strange complaint. I answered all of your questions: "Has this happened anybody else? Why did it happen? And most importantly, how do I get them back?" (actually, sorry, I missed "If so, when did this happen?": I think with 10.6). I also answered a question you did not ask directly, but still needed to know (the rationale for the organization of Python files on OS X). I guess the rhetorical question at the end sounds a bit snarky, but given the language in your question ("an abomination", "missing something?", "have a look-see", etc.), I never expected you would be bothered by it.
    – LaC
    May 29, 2011 at 12:47
  • Sticking it to the man, as we call it, is a common way to express frustration in dealing with technical difficulties. A lot of people do it; that doesn't mean it's a good idea to reply in a similarly accusing way -- I'm a person, Apple is a company. One of us has a brain. I'm sorry to say that I can't really see how you mean you answered all of those questions; "how do I get them back" is perhaps the top priority question here! It could be possible that reinstalling Xcode will bring these back, but it's almost a completely fresh install.
    – lericson
    May 29, 2011 at 22:08
  • 1
    I'm of the "don't dish it out if you can't take it" school. Did you do a full install of Xcode? The headers are contained in the "UNIX Development" package. Try doing a custom install and selecting just that.
    – LaC
    May 29, 2011 at 22:43
  • I don't know how, but somehow the Xcode installer must've skipped installing these headers (and the source-code for the Python standard library..?) even though I'm pretty confident I just told it to do whatever it wanted to by default. Thank you for your time and effort.
    – lericson
    May 30, 2011 at 15:32
1

I have encountered similar problems in the past. Space_C0wb0y's suggestion works for me, and using python_select I can switch between "default" versions of python. This also de-couples me from XCode. I've installed versions of 2.6 and 2.7 using MacPorts, which by default places the distribution in locations such as /opt/local/Library/Frameworks/Python.framework/Versions/2.7. It is the only way I have managed to have consistent installations, including 3rd party modules.

3
  • Well, I'm not sure I'd like to have other versions of Python just because Apple decided to break something. This has worked before, of this I am very, very sure. I really want to know what has happened to a system that used to work.
    – lericson
    May 29, 2011 at 11:49
  • I agree completely, but it is nice to be decoupled from whatever apple decide to do in this respect. I also routinely need to develop and test on 2.6 and 2.7, so the ability to easily switch is good. May 29, 2011 at 11:53
  • I do my testing on a VMware image of Gentoo Linux, so as to not taint the Apple-provided system substrate.
    – lericson
    May 29, 2011 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.