Compiling and Installing pyactivemq on mac osx with macports

I had a hard time trying to configure pyactivemq in my osx box. At the beginning I followed a tutorial written by my friend Andreia Kumpera where she explains what she did on her machine to install pyactivemq (in portuguese). Well, I followed the tutorial and when I tested pyactivemq, I just got a meaningless error message.
I started googling around and couldn’t find much info, maybe pyactivemq is not used a lot in osx environments. I even asked on stackoverflow how could I compile and install pyactivemq. (a question that actually no one answered)
Back to the problem. The error message appeared when pyactivemq was imported, just like below:
$ python
Python 2.5.4 (r254:67916, Jan  5 2010, 17:58:16)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyactivemk
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap
Things got a little bit clearer when I found this page talking about troubleshooting installing mapnik, it has an entry that looked very familiar to my problem of Interpreter not initialized. It says the problem is related to an error linking boost to the python libraries. And, most important, presenting (at least to me) the otool, wich shows every library which your program or library was linked to, after digging around a little bit figuring out how to run otool I was able to run it on my libraries, and what was the surprise when the following came up? Notice that my libraries were linked to apple’s version o python 2.5. After that I’runned it against my copy of pyactivemq and got the same result.
$ otool -L /opt/local/lib/libboost_python-mt.dylib | grep Python
/System/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.1)
$ otool -L build/lib.macosx-10.5-i386-2.5/pyactivemq.so | grep Python
/System/Library/Frameworks/Python.framework/Versions/2.5/Python
After that I tried to import pyactivemq with apple’s python and everything worked.
$ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python src/test/alltests.py
................................................
----------------------------------------------------------------------
Ran 48 tests in 4.795s
OK
Now I knew what the problem was, but not how to solve it. The problem was that something was wrong on macports that made boost compile against system’s python and not macport’s one. Mapnik Troubeshoot page pointed to macports ticket #17975 where the issue was a little better explained. There is also a thred talking about the same problem where I could found some examples of otool usage. If you want to know more about otool, check this and otool man page.
Then I reach macports ticket #17998 which explain in details the problem and points to a possible solution.
$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config
$ ls -ld libpython2.5.a
libpython2.5.a -> /opt/local/Library/Frameworks/Python.framework/Versions/2.5/Python
$ rm libpython2.5.a
$ ln -s ../../../Python libpython2.5.a
$ ln -s ../../../Python libpython2.5.dylib
$ ls -ld libpython*
lrwxr-xr-x    1 root  wheel     15 Jan  6 12:46 libpython2.5.a -> ../../../Python
lrwxr-xr-x    1 root  wheel     15 Jan  6 12:46 libpython2.5.dylib -> ../../../Python
$ otool -L /opt/local/lib/libboost_python-mt.dylib | grep Python
/opt/local/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.0)
$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config
This one alone does not solve the problem. You have to switch the link to macports python. To do this I used:
$ cd /opt/local/lib
$ ls -l ../Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5
$ sudo rm ../Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5
$ sudo mkdir ../Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5
$ sudo cp -R /opt/local/lib/python2.5/* ../Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
$ sudo rm -rf /opt/local/lib/python2.5
$ sudo ln -s ../Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5 python2.5
After that I installed again the boost library, but this time after install, it was correct linkeg agains macports python 2.5
$ sudo port install boost +python25
$ otool -L /opt/local/lib/libboost_python-mt.dylib | grep Python
	/opt/local/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.0)
then I’ve gonne to my pyactivemq distribution, build it again and it was also correct linked. And everything just worked. You should read carefully the macports ticket #17998 because there are some sideeffects of what I just did.
Other References:

http://stackoverflow.com/questions/2013765/compiling-and-installing-pyactivemq-on-osx

http://code.google.com/p/pyactivemq/wiki/Building

Leave a Reply