We have some RedHat boxes which ship with python-2.4 for its own uses like Yum. Its python libraries are in /usr/lib/python2.4. If we try and install another python-2.4 in another location, we've found that at runtime it uses the system's python libraries instead. This plays havoc with our use of a custom python for plone or mod_wsgi or django and whatnot.
I've seen this happen as well when compiling a different python version like 2.6: django under mod_wsgi said it was running my python from its absolute path, but then reported that the python version was 2.4. Deeply disturbing.
When I built these pythons I installed them in locations like /usr/local/python/2.5 and /usr/local/python/2.6. If I used the --enable-shared flag then when I tried to run them, they couldn't find their shared libraries. I could use "ldd" to add their libraries to the systems cache, and that would work so long as there weren't any other same-versioned pythons that needed this. Doing it for 2.4 would have hosed the system python and probably broken yum. So this approach isn't robust and can lead to difficult failures later.
So instead I can use the "-rpath" loader flag at configuration to tell it to link against its own libraries at runtime.
./configure --enable-shared --prefix=/usr/local/python/2.5 LDFLAGS="-Wl,-rpath /usr/local/python/2.5/lib"
Surprise! It fails severely with the misleading message:
checking for C compiler default output file name... configure: error: C compiler cannot create executables
It acts as if setting this rpath is breaking the compiler, as if it now can't find its own libraries. If I first create the (empty) library directory then re-run the configure, it works:
sudo mkdir -p /usr/local/python/2.5/lib
Then invoke the configure command again. After it completes, do the normal make and make install, then you can run your new python and the rpath will tell it to link against the library that was built for it.
Then you can build mod_wsgi against this and it won't complain about python not being able to load its library.