Bug 22503 - GDB uses PYTHONHOME environment variable, but can't find the correct python environment.
Summary: GDB uses PYTHONHOME environment variable, but can't find the correct python e...
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: 7.6
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-27 18:37 UTC by Paul Ferrell
Modified: 2024-06-21 11:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Ferrell 2017-11-27 18:37:57 UTC
When running gdb with PYTHONHOME set to a custom python environment, gdb seems to use that python but can't find the correct environment. The result, as typical when python can't find its environment, is for python to fail on trying to import the site module, giving the following error:
ImportError: No module named site

This appears to apply to all versions of gdb with python support.

The workaround is to run gdb with PYTHONHOME forced to the system python, such as `$ PYTHONHOME=/usr gdb`. This isn't really good enough for us though, as having non-system PYTHONHOME set is standard in our user build environments.

My guess at the fix is for gdb to ignore PYTHONHOME (and probably PYTHONPATH), and always use the python it was built against. The python command line provides a -E option to do exactly that, or you can unsetenv on PYTHONHOME within gdb.
Comment 1 Hannes Domani 2024-06-21 11:23:51 UTC
gdb actually has an equivalent configuration to python -E, if you start it with:

gdb -eiex "set python ignore-environment on"