Skip to content
dagss edited this page Apr 8, 2012 · 5 revisions

Python

Approach 1: Hardlinking/copying executable

If we use hardlinks (same filesystem) or copy the executable (different filesystem) into the profile bin-dir, then Python will pick up site-packages from the profile. However, if you use the system Python, you probably want to use the site-packages on the system as well, so that probably requires a "host-python-packages" wrapper package that would install symlinks to the system python packages as well.

Approach 2: Symlinking and setting PYTHONPATH

If we use a symlink to the Python interpreter, then we need to modify PYTHONPATH. Either by a) always have the user import a PYTHONPATH into the users environment, or b) by, per profile, compile a wrapper binary, as described below, so that only PATH (or the absolute path to the Python binary) is needed.

Creating a PYTHONPATH-setting wrapper

A variation on the symlink approach would be support the system Python by having a small C wrapper changing PYTHONPATH:

#include <unistd.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    setenv("PYTHONPATH", "/foo/bar", 1);
    execv("/usr/bin/python", argv);
}

This binary is debuggable, but gdb doesn't find debug information at startup. Hopefully we can find a way to transplant the debug information from the system Python to the Python wrapper...

Clone this wiki locally