Django (actually MySQL-python) and RPATH
By Chris Quenelle on Jun 20, 2007
A kind soul in the linker group has finally implemented a way to patch Solaris binaries to change their RPATH setting. This will make it much easier for me to cope with the variety Solaris packages I need to assemble to make my various pet projects work. Ali's blog entry shows what it's all about, with a full explanation of both the problem and the solution.
The last time I got bit by this was less than a week ago. I was trying to get django to run on my Solaris desktop. Django is a Python web application framework (named after Django Reinhardt). Django needs a database, I picked MySQL. The python driver for MySQL uses the native MySQL libraries, which I have available in /usr/sfw, cool. I configure the python MySQL driver with a pointer to /usr/sfw/lib, everything builds, but when I run Django, no joy. I eventually figure out it can't find the mysql shared libraries at run time. My best answer last week was to write a start up script wrapper around my Django experiments.
#!/bin/sh export LD_LIBRARY_PATH LD_LIBRARY_PATH=/usr/sfw/lib python manage.py runserver 0.0.0.0:8000
But with Ali's help, I can try to patch the poorly made _mysql.so file to contain the RPATH that it should have had from the beginning. Of course, Python is fun. I dig up /usr/lib/python2.4/MySQL.blah.blah.egg which is a zip file with _mysql.so inside it. I unzip it, patch _mysql.so using rpath, and rezip it, and replace the previous .egg file in /usr/lib. Yippee!! No more need for a start-up script.
Now you might also ask how Python uses a .so file from inside a zip file? A simple pmap command tells us.
% pmap $(pgrep python) | grep mysql FE780000 168K r-x-- /usr/sfw/lib/libmysqlclient_r.so.12.0.0 FE7B8000 88K rwx-- /usr/sfw/lib/libmysqlclient_r.so.12.0.0 FE7E0000 40K r-x-- /home/quenelle/.python-eggs/MySQL_python-1.2.2-py2.4-solaris-2.11-sun4u.egg-tmp/_mysql.so FE7F8000 24K rwx-- /home/quenelle/.python-eggs/MySQL_python-1.2.2-py2.4-solaris-2.11-sun4u.egg-tmp/_mysql.so
Interesting. It seems to dynamically unzip the file into my home directory when a python program needs to use that module. Very clever (in a twisted, inefficient sort of way).