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

Installing Python MySQL connector on MacOS X 10.5

Today I spent a couple of hours trying to get Python MySQLdb connector to work on my Mac OS X 10.5.7. After some search over the internet I found that I should download MySQLdb distribution from SourceForge and compile it locally. I followed Mango Orange’s Installing Python MySQLdb 1.2.2 on Mac OS X. The information here is an addendum as I took a slightly different approach.

Photo by Army Man Chaz

There is a long road to get stuff working

First of all, when I first installed MySQL I took the best version I could use with my computer. So, I got the 64 bit version. Aside all the problems I’ve ever had with 64-bit software, I still make the same mistake.

It turns out that Macs come with 32-bit python installed, and, obviously you cannot link 32-bit code with 64-bit code. So, to get everything working I needed to install a 32-bit version of MySQL, but …

As I’ve already compiled the code, the binaries were already generated, and dist and build directories were not deleted by python setup.py clean. As both directories were removed, compiling and installing was a breeze.

The error I was getting was the following:

Macintosh:MySQL-python-1.2.2 muanis$ python
Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
  import sys, pkg_resources, imp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_mysql)

If you’re getting the same error message, chances are that you’ve got the same problem.

Começando de Novo

Essa deve ser a quarta vez que começo a escrever um blog. Algumas tentativas duraram mais do que outras. Algumas pessoas consideram escrever um dom.

Photo by Leo Reynolds

Scribes table

Eu acredito mais que é um hábito, que se cultivado, se torna natural. Um comentário de um escritor uma vez lembra que quando você começa a ler muito, chega um dia em que precisa escrever para colocar para fora tudo que absorveu.

Eu sempre usei a desculpa de que quando eu resolvia um problema não tinha saco para comentar, partia logo para resolver outro. A verdade é que eu resolvo muitos problemas. Tentar compartilhar um pouco disso aqui talvez seja uma forma de adotar esse hábito saudável.

Outra grande dúvida é sobre escrever em português, inglés ou francês. Meu idioma nativo é o português. Logo fica mais fácil me expressar em pt. Porém escrever em inglês ou francês é uma ótima forma de praticar. Logo os posts aqui possivelmente vão ser uma miscelânea de idiomas.