PDB (Pure Drivel Blog)

Leopard, Python and other wild creatures

Posted by: mishunov on: October 24, 2008

The post is mostly a reminder to myself and contains references to some other posts by other respected developers.

Today I have found out that Philipp von Weitershausen has written the post about the same problem I had a couple of weeks ago and was in the middle of writing the post about the same. Philipp has already explained the problem but I would like to extend it a little (since it’s the note to myself as well):

  • The problem for me showed up not only with Python 2.5, but also with Python 2.4. Since Plone is still using Python 2.4 this is a real problem for me
  • There is no problem when you are using Mac OS X Tiger. Only Leopard
  • There is no problem when you have installed Leopard by updating the Tiger. Problem only strikes clean installations of Leopard
  • Bus Error shows up only in the interpreter shell, but interpreter itself can work well. Means you can not notice the problem if you just run Plone and don’t use Python’s shell as with PDB (not this blog, but python debugger) for example

So, in general, when you install Python in Leopard using MacPorts you are doomed to have Buss Error, since python will pick up broken readline from the system. As Steve McMahon points out in Philipp’s post and Andreas Jung in his own post Leopard uses broken libedit or libreadline (I still don’t get what Leopard is actually using). And that broken library will be caught by your python when you install it with MacPorts.

To avoid the problem I had to do the following steps. They worked for me pretty fine and might work the same nice for you as well. Though it’s not guarantied ;) I also have to point out that I needed Python 2.4, so there might be changes for other versions.

Install new readline

It’s safe to install it with MacPorts:

sudo port install readline

Install Python from source

I have pointed out the problem with readline when you install python with MacPorts on Leopard. So I have decided to build python from source. If you will simply try to download python 2.4 and configure it you can get something like:

lector:Python-2.4.5 denys$ ./configure --prefix=/Users/denys/opt
...
lector:Python-2.4.5 denys$ make
...
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE - ./Modules/posixmodule.c -o Modules/posixmodule.o
./Modules/posixmodule.c: In function 'posix_setpgrp':
./Modules/posixmodule.c:3145: error: too few arguments to function 'setpgrp'
make: *** [Modules/posixmodule.o] Error 1

If you have this, this means you are really using Leopard. And Python 2.4 really can’t be installed in Leopard out-of-the-box. Bah! Even if it sounds silly what you need to do is to explicitly tell python to be installed for Leopard
./configure MACOSX_DEPLOYMENT_TARGET=10.5
But remember we need to point our python to the newly installed readline to avoid Buss Error.

According to Andreas Jung right after configuring your python and before running make you should roughly invade your Makefile. I have no wish to discuss how dirty this solution is, but it works. So, what needs to be done is replacing CC = gcc line in your Makefile to
CSS = gcc -I/opt/local/include -L/opt/local/lib
Then we can finally do
make && make install
If everything went smooth you can try simple test
lector:/ denys$ python2.4
Python 2.4.5 (#1, Oct 31 2008, 22:28:08)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 2+2
4
>>> 2+3
5

Previously (using python installed with MacPorts) you would get Buss Error after “2+3″ request. That’s it about installing python from source in Leopard.

If you plan to use this version of python to run Plone instances, don’t forget to make it your default by putting path to your python in your ~/.profile. Something like

export PATH=/Users/denys/opt/bin:$PATH

Install additional libraries

Of course you would like to have more libraries.

lector:Imaging-1.1.6 denys$ python ez_setup.py

  • PIL. I prefer to install it from source with

lector:Imaging-1.1.6 denys$ python setup.py build_ext -i
...
lector:Imaging-1.1.6 denys$ python setup.py install

  • ZopeSkel

lector:Imaging-1.1.6 denys$ easy_install ZopeSkel

  • pyflakes. Really good checker for simple bugs (typos, wrong indentation, wrong variables etc.) in python.Previously it was possible to install it with easy_install. But these days author does not care a lot about updating product’s page on pypi. So the only one way of installing it is from source. So

lector:Downloads denys$ svn co http://divmod.org/svn/Divmod/trunk/Pyflakes
lector:Downloads denys$ cd Pyflakes/
lector:Pyflakes denys$ python setup.py install

In general, you should have PyFlakes installed at this point. At least I would expect it to. But, if you will try to run pyflakes in your terminal, you will most probably get something like:

...
Traceback (most recent call last):
File "/Users/denys/opt/bin/pyflakes", line 3, in ?
from pyflakes.scripts.pyflakes import main
ImportError: No module named scripts.pyflakes

I have no idea why, but the installation procedure of the Pyflakes does not copy scripts/ folder to your python’s site-packages/pyflakes. So, this is the step you need to do manually – copy scripts/ from your SVN checkout of Pyflakes to your site-packages/pyflakes. In my case it was

lector:Pyflakes denys$ cp -r ~/Downloads/Pyflakes/pyflakes/scripts/ ~/opt/lib/python2.4/site-packages/pyflakes/scripts/

Now your Pyflakes should work properly.

2 Responses to "Leopard, Python and other wild creatures"

Thanks, you saved me :D

You are welcome ;) Glad it was helpful.

Leave a Reply

Tweets

Denys' Photos on Flickr

Eureka! of Hanno Schlichting

Hanno

Hanno Schlichting

More Photos

Denys’ photos on photosight.ru

Денис Мишунов

Pages

 

October 2008
M T W T F S S
    May »
 12345
6789101112
13141516171819
20212223242526
2728293031