This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: [python] proper setting of sys.path
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: archer at sourceware dot org
- Date: Tue, 16 Dec 2008 10:51:50 -0800
- Subject: Re: [python] proper setting of sys.path
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1229453514; bh=CUpb0iAliVv+f6w3Lbo9Xc7xXvU=;h=DomainKey-Signature:MIME-Version:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type: Content-Transfer-Encoding; b=pPt9NyIR8dQNGoO+Y2ymWfrdFvklMIvRDxox3C29VCWV+YqSMMo/L93wWVLTY4kFulJNkhWHT/WuuULEQpKsLg==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=mime-version:in-reply-to:references:date:message-id:subject:from:to:cc:content-type:content-transfer-encoding;b=k8wEBah+80rRyUvR6QUWL/wsTV1qGOU0oHkN7UM8yx0eoa6WDQDzAlmoeeOSVZPR1xCNR8EgtZIONzEbV6DZ4w==
- References: <20081216150307.A5EC53A6B37@localhost> <m3oczct86b.fsf@fleche.redhat.com>
On Tue, Dec 16, 2008 at 8:07 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Paul" == Paul Pluzhnikov <ppluzhnikov@google.com> 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
alternative.
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