rpath alike feature for python scripts

dieter dieter at handshake.de
Wed Jul 30 07:49:46 CEST 2014

Olaf Hering <olaf at aepfle.de> writes:

> On Mon, Jul 28, Albert-Jan Roskam wrote:
>> does this help: https://nixos.org/patchelf.html. It is not specific to Python, though.
> No, this does not help because its not about patching the result.
> The questions is how to obtain the value with should be patched into the
> result.

You wanted to know how to emulate the "rpath" feature with
Python scripts. The use case for the "rpath" feature looks like:
   A binary depends on some shared objects stored at a non-standard
   place. The person linking the binary knows those places
   where the shared objects can likely be found. He uses
   the "rpath" linker option to provide this information.
   It is stored with the created binary and instructs the
   dynamic linker in what additional places it should look
   for shared objects.

Python correspondences:

   binary ~ script
   dynamic linker ~ Python's import mechanism

Python lacks the (static) linking phase. You must invent something:
you may see it as part of script development or as part of the installation
or design it as creating some wrapper which extends the standard
configuration for Python's import mechanism and then call the script

The primary ways to interact with Python's import mechanism
are "sys.path" and the envvar "PYTHONPATH" (which corresponds
to the envvar "LD_LIBRARY_PATH").

> Looks like I have to dissect setup.py and mimic its behaviour in the
> Makefile.

"setup.py" does nothing with Python's "sys.path".

It looks at "sys.prefix" and "sys.execprefix" to learn where
to install modules/packages and binary scripts.

More information about the Python-list mailing list