This is the mail archive of the
mailing list for the Archer project.
[python] proper setting of sys.path
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: archer at sourceware dot org
- Cc: ppluzhnikov at google dot com
- Date: Tue, 16 Dec 2008 07:03:07 -0800 (PST)
- Subject: [python] proper setting of sys.path
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1229439790; bh=5Ku6CiRFd3cXgV4vtfgIoaFeQdg=;h=DomainKey-Signature:To:Cc:Subject:Message-Id:Date:From; b=R6QCXGw48Ka2DXdgFRqBfb2Y/ElcTONqXQkyBjd67I8kfgnMLAbFu7I0ewRd3AHN3kzF2V6kXy2qR/vFGfsl9Q==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=to:cc:subject:message-id:date:from;b=MMpZ1BP3VwzAFlTDCJuYUPPwA6eWFUsjkq7pueWxBdL4NhPUHHy691EIFsUGzkqsAvPYfbhMIv8Fi42GW37fPA==
While trying to use libstdcxx/v6/printers.py, I've encountered a
$ ./gdb -q -ex 'python import itertools'
Traceback (most recent call last):
File "<string>", line 1, in ?
File "/usr/local/buildtools/current/sitecustomize/sitecustomize.py", line 248, in SetupPathsAndImport
return real_import(name, globals, locals, fromlist)
ImportError: /usr/lib/python2.4/lib-dynload/itertools.so: cannot open shared object file: No such file or directory
Error while executing Python code.
This is happening because /usr/lib/python2.4/... exists, but contains
32-bit python modules. My GDB is 64-bit, and was linked using python
configured with --prefix=$HOME/python2.4 and installed there.
Now, I can easily work around this by setting PYTHONPATH, but it
would be nice if I didn't have to do that. Python in $HOME/python2.4
certainly knows how to find its modules.
AFAICT, what's happening is this:
- GDB doesn't call Py_SetProgramName(), so 'progname' in Python/pythonrun.c
continues to be "python"
- When Py_Initialize() is called, PATH is searched, /usr/bin/python
is found, and /usr/lib/python2.4 is deemed to contain standard modules.
Adding a call to Py_SetProgramName("you are unlikely to find this on PATH")
before the call to Py_Initialize() fixes the problem: python can't
find an executable named "you are unlikely ..." on PATH, and uses
PREFIX compiled into it (which is exactly the desired behavior).
But surely there should be a better way to fix this?