About this blog…

I am employed by Netnod as head of engineering, research and development and am among other things chair of the Security and Stability Advisory Committee at ICANN. You can find CV and photos of me at this page.

As I wear so many hats, I find it being necessary to somewhere express my personal view on things. This is the location where that happens. Postings on this blog, or at Facebook, Twitter etc, falls under this policy.

The views expressed on this post are mine and do not necessarily reflect the views of Netnod or any other of the organisations I have connections to.

Python 3.2.1 on MacOSX 10.7.1

Getting a proper version of python 3.x installed is not as easy as it has been earlier. First of all, you need the Developer package installed (again). This you do by installing XCode 4.x from the MacApp store. I thought I had done so, but could still not find gcc etc in my path. Some people on the net say one should just produce soft links here and there, but I think that would still create those with Xcode 3.x.

Anyone I found that in Launchpad (this weird thing that I do not know what it is really) there was an Install XCode App. I did run it but although it crashed XCode when later running it, it seems to have installed the tools I needed. Make, gcc etc all was where I wanted them.

Next, I of course downloaded Python from the official download page. I did though detect early that that is built without support for wide Unicode characters, so I had to try to built it myself. Here is where things started to go south, although I was successful in the end.

To build Python, you want to have GNU gettext and readline libraries. Both sort of install after ./configure;make;make install, but readline was a problem:

i686-apple-darwin11-llvm-gcc-4.2: -compatibility_version only allowed with -dynamiclib

Some use of Google made me find that someone else had had this problem before, but that was when MacOS based on Darwin 9 was released. You can find what Lucian E. Marin wrote here.

So, up with the editor and change support/shobj-conf to also support Darwin11:

$ diff support/shobj-conf support/shobj-conf~
< darwin[89]*|darwin10*|darwin11*)
> darwin[89]*|darwin10*)
< 	darwin[789]*|darwin10*|darwin11*)	SHOBJ_LDFLAGS=''
> 	darwin[789]*|darwin10*)	SHOBJ_LDFLAGS=''

After that, building Python was easy with the following config directive:

$ ./configure --with-wide-unicode --enable-ipv6 --enable-framework

As you can see, I now have the unicode support I wanted:

$ uname -a
Darwin junior.frobbit.se 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11
PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64
$ which python
$ python   
Python 3.2.1 (default, Aug 22 2011, 13:53:40) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxunicode

5 comments to Python 3.2.1 on MacOSX 10.7.1

  • Can I just be veeeeery pedantic and point out that the diff above is reversed… :-)

    • paf

      Nope, the file with ~ at the end is the old file (backup from Emacs) while the file without is the new version. Sure, it might not be so that you can run patch automatically… That is one of the reasons I did not run -c.

  • Mark

    When I try to build gettext- on Mac OS X 10.7.1 it dies with

    stpncpy.c:34: error: expected declaration specifiers or ‘…’ before numeric constant
    stpncpy.c:34: error: expected ‘)’ before ‘!=’ token
    stpncpy.c:34: error: expected ‘)’ before ‘?’ token
    make[4]: *** [stpncpy.lo] Error 1
    make[3]: *** [all] Error 2
    make[2]: *** [all-recursive] Error 1
    make[1]: *** [all] Error 2
    make: *** [all-recursive] Error 1

    • paf

      Ensure you do not have any old libraries laying around, for example in /opt after running macports or something.

  • Mark

    Nope nothing like that, it’s on a brand new Mac Mini so it’s just a plain Lion server install plus Xcode.