I\'m trying to build multiple versions of python using Pythonbrew, but I\'m getting some test failures. This is on a VM running: Ubuntu 8.04 32bit
Ryan Thompson's answer is good ... LD_RUN_PATH
is the proper remedy.
However, rather than hardcoding an absolute path, one can instead use:
LD_RUN_PATH='$ORIGIN/../lib'
... where $ORIGIN
is the PWD
of the running binary (eg. python).
# objdump -x /home/arisinger/.pythonbrew/pythons/Python-2.7.3/bin/python|grep RPATH
RPATH $ORIGIN/../lib
# ldd .pythonbrew/pythons/Python-2.7.3/bin/python
[...]
libpython2.7.so.1.0 => /home/arisinger/.pythonbrew/pythons/Python-2.7.3/bin/../lib/libpython2.7.so.1.0 (0x00007f43994f6000)
[...]
... the above will also properly install pip, etc. Lastly, from man ld.so
:
$ORIGIN and rpath
ld.so understands the string $ORIGIN (or equivalently ${ORIGIN}) in an
rpath specification (DT_RPATH or DT_RUNPATH) to mean the directory con‐
taining the application executable. Thus, an application located in
somedir/app could be compiled with gcc -Wl,-rpath,'$ORIGIN/../lib' so
that it finds an associated shared library in somedir/lib no matter
where somedir is located in the directory hierarchy. This facilitates
the creation of "turn-key" applications that do not need to be
installed into special directories, but can instead be unpacked into
any directory and still find their own shared libraries.
EDIT: sadly venvs breaks because virtualenv copies the python
binary (changing $ORIGIN
), but does not copy (or symlink) the library, so C/builtin dynamic modules in the venv end up linking to the system python ... ungood :-( ...
... IMO this is a bug to be fixed (in virtualenv?), but an easy workaround is to manually copy/symlink libpythonX.Y.so*
into the lib/ dir of the venv ... or do something a little yucky looking like (note X.Y.Z):
LD_RUN_PATH='$ORIGIN/../lib:$ORIGIN/../../../../pythons/Python-X.Y.Z/lib'
... pick whatever is less nasty to you; both verified to work.