Upgrading to Snow Leopard Part 1: Python


7375E4A0-BEFE-4AD1-9693-DE1E5F0716BF.jpgOK, I know everyone is talking about Snow Leopard but I figured I ought put something up here for all the Google searchers struggling with more technical upgrades. First off Python is now 2.6.1. No it obviously didn’t upgrade all your modules. So let me tell you how to solve that problem — it ends up being more complex than it first appears. Then I’ll address other issues in a subsequent post. There are a few gotchas.

First, you must install the XCode install. It’s not installed by default. If you get an error “unable to execute gcc-4.2: No such file or directory” that is probably the problem. (Yeah, I was an idiot at first trying to upgrade things)

Next the old Python 2.5 libraries are actually still there. Look in /LibraryPython/2.5/site-packages. The easiest way to reinstall them is just to run easy_install, where applicable. (Not all my modules were put in the easy_install repositories)

For me I’ve done the following: (Feel free to cut and paste as all these are pretty useful modules and many of my scripts depend upon them)

sudo easy_install appscript
sudo easy_install MySQL-python
sudo easy_install pysqlite
sudo easy_install titlecase
sudo easy_install PdbTextMateSupport
sudo easy_install simplejson
sudo easy_install mako
sudo easy_install numpy
sudo easy_install scipy
sudo easy_install ipython
sudo easy_install Matplotlib
sudo easy_install SymPy

There were a few others there (including several Levenshtein distance modules) but I decided that several I just didn’t need. If I find a script that needs them I may reinstall.

Most of the above are fairly easy to understand I suppose.

Titlecase is what I use to fix titles in iTunes.

Pysqlite reads a common database format used by many Mac and iPhone applications.

MySQL-python is a Python module for working with MySQL, a far more powerful database. (Often used by blogging software like WordPress but quite useful as a full database)

Simplejson reads a structured Python like dictionary into a Python dictionary. (I used it in my get iTunes album name script to access the iTunes store database)

PdbTextMateSupport provides rudimentary debugging features to TextMate.

Mako is a template library I use to auto-generate HTML mail for invoices.

NumPy and SciPy are scientific computing modules. I don’t use them that often, but when I do… NumPy is also used in Sage, a free open source Mathematica alternative, which makes use of Python and iPython extensively. (I should add that while it’s $3000 cheaper than Mathematica it is nowhere near as good) Note that SciPy requires fortran and a few other MacPorts installs. (We’ll cover that next)

Matplotlib is a nice graphing system.

SymPy is something I’ve not used but which I’ve been curious about for quite some time. It’s a “pure Python” alternative to Sage which in turn is an alternative to Mathematica. Check out the tutorial to decide if you’re interested.

The PyObjC is a tad different as it comes with Snow Leopard. I’ve not played around with it yet. Probably checking the PyObjC website every now and then for the latest version would be wise.

After all this I cleaned out the Python 2.5 module directory.

Related posts:

  1. Upgrading to Snow Leopard Part 4: MySQL
  2. Upgrading to Snow Leopard Part 5: The Python Gripes
  3. Upgrading to Snow Leopard Part 3: MacPorts
  4. Upgrading to Snow Leopard Part 2: Minor Tips
  5. Upgrading to Snow Leopard Part 6: 64bit vs. 32bit
  6. Upgrading to Snow Leopard Part 7: One Month Later
  7. To Python 3 part 2
  8. To Python 3 part 3: 3 Denied
  1. #1 by Joseph Smidt on 2009/08/28 - 11:04 pm

    THANK YOU FOR THIS!!! On Monday this information will be vital. (My research depends on getting Python to work correctly. Thank heavens I will be able to use 2.6)

  2. #2 by Clark on 2009/08/28 - 11:22 pm

    Since the above probably aren’t the only libraries people need, referring to PyPi is useful as it lists most public common modules.

  3. #3 by Dr. Drang on 2009/08/29 - 9:40 am

    Hmmmm… I haven’t installed Snow Leopard yet, but my plan was to try copying the contents of 2.5/site-packages to 2.6/site-packages. I suppose I’d have to delete all the .pyc files and let them recompile under 2.6, but overall that seems simpler than trying to figure out all the nonstandard modules I use.

    Is there some reason copying wouldn’t work?

  4. #4 by Clark on 2009/08/29 - 9:47 am

    Probably it would, but I depend upon them so I figured, why tempt fate? Plus it ensures I have the latest versions.

    I’m pretty conservative on these matters. For instance the first thing I do before installing an OS upgrade is back everything up to a bootable external disk. I’ve just had too many nightmares in the past with things going wrong.

  5. #5 by David on 2009/08/29 - 1:55 pm

    I upgraded to snow leopard and xcode 3.2 and unfortunately the new project templates seem to be missing the pyobjc templates. Do you have any idea how to get them?

  6. #6 by PJ on 2009/08/29 - 2:41 pm

    Has the source for MySQLdb moved on sourceforge?

    If I run the command:

    sudo easy_install MySQL-python

    I get the following error


    error: Can't download http://dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3c1.tar.gz: 404 Not Found

    I have a fresh Snow Leopard install and just installed the 64-bit version of Mysql 5 for os x.

  7. #7 by clark on 2009/08/30 - 8:26 pm

    Weird. It’s doing that now for me too. When I go to directly download it gives me zmysql-python which is for Zope. I just checked my /Library and it’s not in there either. So I must have not noticed the 404 error when downloading.

    I’ve not been able to find an answer. I’ll see about using MacPorts (which was going to be tonight’s post anyway).

    David, I don’t use XCode with Python so I can’t speak there. I always use TextMate although I’ve been experimenting with Eclipse and Komodo.

  8. #8 by Clark on 2009/08/30 - 9:34 pm

    OK, the source code is now available here.

  9. #9 by PJ on 2009/08/30 - 11:26 pm

    Got it installed. Next problem child, getting PIL installed for Python 2.6 on Snow Leopard. :)

  10. #10 by clark on 2009/09/01 - 5:57 pm

    Do you like using PIL over easy_install? I’ve been intrigued since the developer said easy_install will never work with Python 3.x.

  11. #11 by PJ on 2009/09/01 - 11:42 pm

    I’ve got it installed quite easily actually. You can read how I did it here.

  12. #12 by clark on 2009/09/02 - 11:04 am

    OK, sorry, I confused PIL (Python Imaging Library) with py-pip which is the easy_install alternative.

    I downloaded Pip and tried installing a few packages with it. It actually found pil but had errors with it. So I don’t think Pip is quite ready for prime time. (The errors were related to pip itself and not the pil library)

  13. #13 by Zane Selvans on 2009/09/03 - 9:43 pm

    Did you have any issues getting readline to work with iPython? It is stubbornly refusing for me. Gah.

  14. #14 by clark on 2009/09/03 - 9:46 pm

    No. None at all. I can’t even recall what I did. I think one of the easy_installs I did also installed readln but I can’t recall which. Try doing an easy_install on iPython and see if that works for you.

  15. #15 by Zane Selvans on 2009/09/04 - 12:19 am

    Unfortunately the readline that comes from easy_install seems to be hard-coded to work with Python 2.5.1 from OS X 10.5, and fails to figure out that the architecture has changed for 10.6. However, I was able to download it with –editable and force it to build i386 and x86_64 libraries, and then create the egg, and it seems to be working okay now… finally!

  16. #16 by clark on 2009/09/04 - 4:06 pm

    I did some poking around and I thought it had installed when it hadn’t and iPython was using Apple’s hack to emulate readline.

    I downloading readline the following way.

    wget ftp://ftp.cwru.edu/pub/bash/readline-6.0.tar.gz
    tar -xvzf readline-6.0.tar.gz
    cd readline-6.0
    ./configure
    make
    sudo make install
    

    However I’m having trouble convincing iPython to use readline rather than libedit.

  17. #17 by Sarp Erdag on 2009/09/08 - 1:20 pm

    Hello, I also installed PIL without problems but the _imaging c library is giving me trouble. Anyone tried importing it in the python shell?

    In my apps I get this error:
    The _imaging C module is not installed

    And over the shell:

    Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> from PIL import image
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: cannot import name image
    >>> from PIL import Image
    >>> import _imaging
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
    Referenced from: /Library/Python/2.6/site-packages/PIL/_imaging.so
    Expected in: flat namespace
    in /Library/Python/2.6/site-packages/PIL/_imaging.so
    >>>

  18. #18 by Clark on 2009/09/08 - 10:16 pm

    It’s looking to me like some aspects of Python just aren’t ready quite ready for prime time. Keeping Python2.5 around from your backup disk has been working for me. But it definitely is frustrating.

    It seems to me that the issues with uname are the cause of some problems (since OSX has a 32 bit kernel but is a 64 bit OS)

    I suspect some of these problems may take a few weeks to work out unfortunately.

  19. #19 by Ryan on 2009/09/08 - 10:46 pm

    I’m have the exact same issue with PIL.

  20. #20 by Chester Kwok on 2009/09/12 - 7:25 am

    Finally got readline to install on snow leopard.

    I used the -editable command on easy_install and then commented out the first four lines in readline/rl/build.sh and it worked.

  21. #21 by clark on 2009/09/14 - 11:36 am

    I got it installed fine. I just couldn’t get programs like iPython to recognize it. Did you get iPython to use it?

  22. #22 by Chanita on 2009/10/14 - 7:27 am

    I also get “The _imaging C module is not installed” problem.

  23. #23 by g on 2009/10/20 - 8:03 am

    me too :(

    “The _imaging C module is not installed”

    anyone got any suggestions?

  24. #24 by chanita on 2009/10/21 - 12:07 am

    Chaiwat help me out and wrote on his blog:

    http://proteus-tech.com/blog/cwt/install-pil-in-snow-leopard/

(will not be published)