When trying to run a python script, I get the error AttributeError: \'module\' object has no attribute \'pydebug\'. I am using Python 2.6.
Full error:>
I receive the error when running gdb on a Ubuntu system where an alternative version of Python has been installed and is being preferred by the linker. You can verify whether this is happening in your case by using ldd to ask which libraries gdb is using:
# ldd $(which gdb)
...
libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0x00007ff75e044000)
...
You can see that the off-brand version of Python running in /usr/local/lib is supplying libpython to gdb instead of the official Ubuntu Python in /usr/lib which is causing the error — whatever off-brand Python this is in /usr/local must not have been compiled in the same way that the Ubuntu Python was compiled, and so the expectations of gdb are being disappointed.
The solution is to use the environment to control the linker’s behavior and make it prefer the system libpython. For good measure, I also reset my PATH back to something utterly standard. I find that this works:
PATH=/bin:/usr/bin LD_LIBRARY_PATH=/usr/lib gdb ...