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]

[python] proper setting of sys.path


While trying to use libstdcxx/v6/, I've encountered a
small problem:

$ ./gdb -q -ex 'python import itertools'           
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "/usr/local/buildtools/current/sitecustomize/", line 248, in SetupPathsAndImport
    return real_import(name, globals, locals, fromlist)
ImportError: /usr/lib/python2.4/lib-dynload/ cannot open shared object file: No such file or directory
Error while executing Python code.
(gdb) q

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?


Paul Pluzhnikov

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