Home > computers > Installing Python 3 on Mac OS X Leopard

Installing Python 3 on Mac OS X Leopard

python

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:
    ./configure
    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

Categories: computers Tags: , , ,
  1. Matt
    December 6th, 2008 at 19:59 | #1

    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. December 6th, 2008 at 21:00 | #2

    Glad it helped ;)

  3. December 6th, 2008 at 23:18 | #3

    What Matt says! Thanks for posting!

  4. December 11th, 2008 at 11:28 | #4

    Good tip. I posted a similar recipe that uses readline from MacPorts, which may be convenient for some people. http://chrismiles.livejournal.com/25648.html

  5. Eino Makitalo
    December 13th, 2008 at 21:25 | #5

    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. December 14th, 2008 at 01:12 | #6

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

  7. Alex Krycek
    December 14th, 2008 at 09:20 | #7

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

  8. December 14th, 2008 at 10:34 | #8

    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
    January 2nd, 2009 at 02:48 | #9

    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.

    help?

  10. Chris
    January 13th, 2009 at 01:05 | #10

    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. January 13th, 2009 at 01:51 | #11

    @jksdoo:
    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
    January 16th, 2009 at 00:20 | #12

    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!

    SImon

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

  13. February 4th, 2009 at 23:36 | #13

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

  14. Jim
    February 5th, 2009 at 00:51 | #14

    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. February 5th, 2009 at 01:13 | #15

    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 ftp://ftp.cwru.edu/pub/bash/readline-5.2.013.tar.gz (I think you don’t need to apply any patch to it) :)

  16. expora
    February 5th, 2009 at 08:59 | #16

    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 ;)

    Cheers!

  17. February 5th, 2009 at 14:29 | #17

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

  18. David S.
    February 6th, 2009 at 07:37 | #18

    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
    February 9th, 2009 at 22:05 | #19

    @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?

    Cheers,

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

  20. February 9th, 2009 at 22:17 | #20

    @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
    February 9th, 2009 at 23:03 | #21

    @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 :)

    Cheers!

  22. Greg
    February 10th, 2009 at 15:48 | #22

    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 \
    -ldl

  23. February 10th, 2009 at 19:34 | #23

    @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
    February 12th, 2009 at 10:53 | #24

    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. February 12th, 2009 at 15:17 | #25

    @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
    February 16th, 2009 at 00:52 | #26

    @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
    sys.exit()

    Happy hacking ;)

  27. May 7th, 2009 at 09:39 | #27

    well.. it’s like I said!

  28. Mark
    January 16th, 2010 at 01:02 | #28

    Readline seemed to install nicely, but…

    gcc Python.framework/Versions/3.0/Python -o python.exe \
    Modules/python.o \
    -ldl
    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. May 24th, 2010 at 21:16 | #29

    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?

  1. No trackbacks yet.