Installing Python 3 on Mac OS X Leopard

Posted by Arkham on December 6th, 2008


It’s a long time (almost a month!) I don’t write here anymore, but I’ve come back to teach you how to install Python 3.0 with readline support on Mac OS X 10.5 “Leopard” (incidentally I bought a Macbook :P )

  1. Download the latest readline from the GNU readline homepage.
  2. Extract it in a folder.
  3. Download all the patches available here and save them in the same folder.
  4. Open Terminal and enter in that folder.
  5. Apply all the patches by running:
    patch -p0 < patch_file_name

    For example:

    patch -p0 < readline52-001
    patch -p0 < readline52-002
    patch -p0 < readline52-003
  6. Configure, make and install:
    make && sudo make install
  7. Download the latest Python 3 release from here.
  8. Extract it and navigate to the folder with Terminal.
  9. Configure it by running:
    ./configure --enable-framework --with-readline-dir=/usr/local
  10. Compile and install it:
    make && sudo make frameworkinstall

Here you go! :D

This entry was posted on Saturday, December 6th, 2008 at 00:35 and is filed under computers. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Tags: , , ,

29 Responses to “Installing Python 3 on Mac OS X Leopard”

  1. Matt Says:

    This was very helpful! Thank you for posting these instructions. They’re useful for me as a beginner with Python (trying to start out on the latest version).

  2. Arkham Says:

    Glad it helped ;)

  3. Stephen Says:

    What Matt says! Thanks for posting!

  4. Chris Miles Says:

    Good tip. I posted a similar recipe that uses readline from MacPorts, which may be convenient for some people.

  5. Eino Makitalo Says:

    I follow the instructions, but with my 10.5.5 I had to compile and install readline with command

    6. ./configure
    make static && sudo make install-static

    It gave me some error “-compatibility_version only allowed with -dynamiclib”

  6. Arkham Says:

    Oh, are you sure you did apply all the patches (especially the number 12)?

  7. Alex Krycek Says:

    How would I get readline support if I already have Python 3.0 installed? Thanks.

  8. Arkham Says:

    Hey Alex, I’m sorry but I suppose that you have to repeat the whole procedure since the path for the readline library is being set up during the configure and I don’t know if there is an easy way to fix it once installed ;)

  9. jskdoo Says:

    Will this work with ox 10.5.6?

    When I tried it I got this:

    patch unexpectedly ends in middle of line
    patch: **** Only garbage was found in the patch input.


  10. Chris Says:

    Great! That really helped as there is no easy .pkg as there is for 2.6
    One small question: I also have 2.6 installed and want to keep it that way. Will I run into any conflicts?

  11. Arkham Says:

    Are you running the patches correctly? Once you have downloaded all the patches in the same folder you have extracted the python tarball, you should type:
    patch < readline52-001 patch < readline52-002 patch < readline52-003 and so on.. @Chris: There shouldn't be any problems since all the files belonging to the Python 3.0 environment are saved into /Library/Frameworks/Python.framework folder into a separate destination ;)

  12. SimonW Says:

    Excellent tips, thank you.
    Everything seemed to go smoothly with the readline and subsequent Python install, and I can run Python3.0. Great!

    Trouble is I can’t run IDLE because of some Tk version conflict. I likely caused this myself with some Tcl/Tk install a while back … but how to fix? Error message at end.

    The only Tk 8.5 I can find on the machine is in /Library/Frameworks… while /System/Library/Frameworks… has 8.4

    Can IDLE3.0 be made to run in this situation? What to do?

    Thanks very much!


    Traceback (most recent call last):
    File “/usr/local/bin/idle3.0”, line 5, in
    File “/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/idlelib/”, line 1371, in main
    root = Tk(className=”Idle”)
    File “/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/tkinter/”, line 1640, in __init__
    File “/Library/Frameworks/Python.framework/Versions/3.0/lib/python3.0/tkinter/”, line 1653, in _loadtk
    % (_tkinter.TK_VERSION, tk_version))
    RuntimeError: tk.h version (8.4) doesn’t match libtk.a version (8.5)

  13. Arkham Says:

    @SimonW: I don’t know how to solve that, but maybe you could try to install python3 using macports ;)

  14. Jim Says:

    patch readline-012 doesn’t seem to work – ‘patch’ comes back with a prompt
    saying “What file do you want me to patch?”

    All of the other patch files seem to include the file to patch…

    Skipping patch readline-012 and moving on to 013, 013 works, but a subsequently build fails due to some conflict between -compatibility-with and the -dynamiclib option.

    I’m guessing this is fixed by 012, which didn’t get applied.

  15. Arkham Says:

    I can’t seem to be able to download the readline tarball, so at the moment my guess is to try with the name of the file included in the patch, aka support/shobj-conf
    If it doesn’t work, try this new readline release (I think you don’t need to apply any patch to it) :)

  16. expora Says:

    I also had problems trying to apply patch 12. Then I tried the -p option with every file and it worked; something like…

    patch -p0 < readline52-001

    It compiled just fine ;)


  17. Arkham Says:

    @expora: Thanks! I’ve modified the howto :)

  18. David S. Says:

    Wow! Thanks! I’ve been wanting 3.0 on my Mac, but the Python site just referred me to the Wiki site. Said nothing about “if you want to go to a little effort, here are the ingredients.” I found your article and now all is well with the world.

  19. expora Says:

    @Arkham: Thank you!

    I just have a few doubts. Do we need to compile against readline(3)? From the Python manual included in Leopard I read it works with editline(3). I did a:

    $ ls -l /usr/lib | grep readline

    and I can see there’s a link from libreadline to libedit:

    lrwxr-xr-x 1 root wheel – 15B Feb 2 02:35 libreadline.dylib@ -> libedit.2.dylib

    If we compile Python 3.0 with no –with-readline-dir, do we get a Python with editline support?

    Man, but readline is so wicked already!

    And, is the –with-readline-dir a common configure option in GNU software? Is it documented in Python?


    P.D.: Everybody, please excuse my english, I try my best ;)

  20. Arkham Says:

    @expora: Python’s interactive interpreter usually doesn’t support commands history, auto completion and auto indentation: compiling it against readline adds these functions. Mac OS X uses in fact libeditline by default even if it offers a lot less functionalities, just because it is BSD-licensed while libreadline is “tainted” by the GPL.
    And I’ve found out about “–with-readline-dir” searching on Internet and it seems undocumented but nonetheless apparently existing :D

  21. expora Says:

    @Arkham: Thanks for the info. That’s what I thought (about the command line functionality). I read something about the BSD license in the default Python manual, I think. All in all it’s just burocracy.

    I’ll stay with readline support, which goes pretty well with my bash setup. I even got history-search-backward (and forward) and other stuff through bindings in my .inputrc. Very nice indeed. I guess you can configure that sort of thing with editrc but didn’t want to learn another set of functions for now (I’m a Unix newbie and already studying enough subjects).

    It’s a shame Python docs do not mention the readline configure option. I’m glad you posted this :)


  22. Greg Says:

    Does this work on PPC as well as x86? My poor PowerBook seems to hang every time I get to:

    gcc Python.framework/Versions/3.0/Python -o python.exe \
    Modules/python.o \

  23. Arkham Says:

    @Greg: I’m sorry, but I tested this only on a x86 Macbook, and I have no idea on how to make it work for PPC..

  24. Alan Williams Says:

    Far and away too difficult for me. I have used macs 20 years but have no Terminal experience.
    I guess Python is not so simple after all.

  25. Arkham Says:

    @Alan Williams :
    I guess there is nothing wrong in learning something new after 20 years of Mac experience. And no, python is not visual basic.

  26. expora Says:

    @Alan Williams

    You don’t need to install Python 3.0 to explore the language. Why don’t your try the default python installation (version 2.5.1).
    Just open terminal, type python and press enter. To exit type Ctrl-D or type these lines (followed by enter):

    import sys

    Happy hacking ;)

  27. Tweldig Says:

    well.. it’s like I said!

  28. Mark Says:

    Readline seemed to install nicely, but…

    gcc Python.framework/Versions/3.0/Python -o python.exe \
    Modules/python.o \
    ld: warning: in Python.framework/Versions/3.0/Python, file is not of required architecture
    Undefined symbols:
    “_PyMem_Malloc”, referenced from:
    _main in python.o
    _main in python.o
    _main in python.o
    “_Py_Main”, referenced from:
    _main in python.o
    _main in python.o
    “_PyMem_Free”, referenced from:
    _main in python.o
    _main in python.o
    _main in python.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [python.exe] Error 1

  29. Mtmm Says:

    This seems to be getting me further than any other website that talks about installing the latest Python. I seem to still be having trouble though. In the terminal, I get the correct file directory for the patch, however I get this error message

    “patch unexpectedly ends in the middle of line
    patch: **** Only garbage was found in the patch input.”

    What do you think I am doing incorrectly?