This is the mail archive of the mailing list for the Archer project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [python] proper setting of sys.path

On Tue, Dec 16, 2008 at 8:07 AM, Tom Tromey <> wrote:

>>>>>> "Paul" == Paul Pluzhnikov <> writes:
> Paul> Adding a call to Py_SetProgramName("you are unlikely to find
> Paul> this on PATH") before the call to Py_Initialize() fixes the
> Paul> problem: python can't find an executable named "you are unlikely
> Paul> ..." on PATH, and uses PREFIX compiled into it (which is exactly
> Paul> the desired behavior).
> Paul> But surely there should be a better way to fix this?
> From the Python API reference, it sounds as though we ought to call
> Py_SetProgramName(argv[0]) early on.
> Will this work for your case?

Yes, I've looked at this as well, and doing so would require
that argv[0] be passed to all the _initialize_YYYY(), which are
auto-generated from a sed script.

Yes, this would work in my case, but only so long as I don't copy
the GDB/Py binary into /usr/bin. As soon as I do that, I'd be back
to square one :(

An alternative which will continue to work regardless of where my
GDB binary is copied, is to use $HOME/python2.4/bin/python in call
to Py_SetProgramName() (where the path to python is the one which
was detected at GDB configure time).

Another alternative is to putenv("PYTHONPATH=...") before calling
Py_Initialize(), where "..." is again determined at configure time.
This has the disadvantage that the user now can't override
compiled-it value with his own PYTHONPATH, so I don't like this

I think that the root cause of the difficulty is that python is
using a heuristic to find modules, and the heuristic works well
when argv0 is the interpreter, but less well when argv0 has nothing
to do with the interpreter being used.

Yet another alternative is to remove assumption about availability
of standard python modules. In the past, you could just copy the
single GDB binary to target system, and it worked (i.e. there was no
"make install" requirement). And now we are breaking that :(

Paul Pluzhnikov

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]