AttributeError: object 'module' does not have attribute 'pydebug'

When I try to run a python script, I get the AttributeError: 'module' object has no attribute 'pydebug' error message. I am using Python 2.6.

Full error:

 File "/lib/python2.6/distutils/sysconfig.py", line 238, in get_makefile_filename return os.path.join(lib_dir, "config" + (sys.pydebug and "_d" or ""), "Makefile") AttributeError: 'module' object has no attribute 'pydebug' 
+4
source share
4 answers

I think that everything you are trying to run is expected to be used with a special python debug build. sys.pydebug is not usually found in the standard release of the sys module, and I believe that it will be there if you built debug python:

http://docs.python.org/c-api/intro.html#debugging-builds

Perhaps this could also be part of the specific build that Debian / Ubuntu distributions use.

+2
source

I ran into this problem when trying to run gdb on a Ubuntu 12.04.1 system on the python I created. I expect Ubuntu to build some hooks on the gdb system to use the debug version of Python; but the hooks don't snap on anything on my own python. I went around this by creating my own gdb and doing this.

Here is the command line and full trace:

 price@neverland :~/LSST/ip_diffim[master] $ gdb --args python tests/SnapPsfMatch.py Traceback (most recent call last): File "/usr/lib/python2.7/site.py", line 562, in <module> main() File "/usr/lib/python2.7/site.py", line 544, in main known_paths = addusersitepackages(known_paths) File "/usr/lib/python2.7/site.py", line 271, in addusersitepackages user_site = getusersitepackages() File "/usr/lib/python2.7/site.py", line 246, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File "/usr/lib/python2.7/site.py", line 236, in getuserbase USER_BASE = get_config_var('userbase') File "/usr/lib/python2.7/sysconfig.py", line 577, in get_config_var return get_config_vars().get(name) File "/usr/lib/python2.7/sysconfig.py", line 476, in get_config_vars _init_posix(_CONFIG_VARS) File "/usr/lib/python2.7/sysconfig.py", line 337, in _init_posix makefile = _get_makefile_filename() File "/usr/lib/python2.7/sysconfig.py", line 331, in _get_makefile_filename return os.path.join(get_path('platstdlib').replace("/usr/local","/usr",1), "config" + (sys.pydebug and "_d" or ""), "Makefile") AttributeError: 'module' object has no attribute 'pydebug' 

it looks like it is looking for the wrong python (in /usr/lib ), even though I told the system not to do this:

 price@neverland :~/LSST/ip_diffim[master] $ which python /home/price/eups/Linux/python/2.7.2/bin/python price@neverl and:~/LSST/ip_diffim[master] $ echo $PYTHONPATH | grep usr price@neverland :~/LSST/ip_diffim[master] $ 
+3
source

I get an error when starting gdb on an Ubuntu system where an alternative version of Python was installed and is preferred by the linker. You can check if this happens in your case using ldd to ask which gdb libraries:

 # ldd $(which gdb) ... libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0x00007ff75e044000) ... 

You can see that the non-tagged version of Python running in /usr/local/lib supplies libpython in gdb instead of the official Ubuntu Python in /usr/lib , which causes an error - something like untagged Python is in /usr/local , doesn't have to be compiled the way Ubuntu Python was compiled, and therefore gdb expectations are disappointing.

The solution is to use the environment to control the behavior of the linkers and make it preferred by the libpython system. For good measure, I will also reset my PATH back to something completely standard. I believe this works:

 PATH=/bin:/usr/bin LD_LIBRARY_PATH=/usr/lib gdb ... 
+2
source

In Ubunut-12.04, embedded binaries with the pyinstaller installation call "site.py" from the python host installation, the call trace tries to get the value "sys.pydebug".

 $ python Python 2.7.3 (default, Feb 27 2014, 19:58:35) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.pydebug False 

Problem created based on embedded python.

HACK: To make pyinstaller executables on Ubuntu-12.04. Added below code change in custom python that returns zero for "sys.pydebug".

 $ diff -Naur Python/sysmodule-org.c Python/sysmodule.c --- Python/sysmodule-org.c 2018-03-15 09:37:26.539515000 -0700 +++ Python/sysmodule.c 2018-03-15 19:58:34.503031000 -0700 @@ -1106,6 +1106,7 @@ maxunicode -- the largest supported character\n\ builtin_module_names -- tuple of module names built into this interpreter\n\ version -- the version of this interpreter as a string\n\ +pydebug -- always return zero\n\ version_info -- version information as a named tuple\n\ hexversion -- version information encoded as a single integer\n\ copyright -- copyright notice pertaining to this interpreter\n\ @@ -1420,6 +1421,8 @@ SET_SYS_FROM_STRING("version", PyString_FromString(Py_GetVersion())); + SET_SYS_FROM_STRING("pydebug", + PyInt_FromLong(0)); SET_SYS_FROM_STRING("hexversion", PyInt_FromLong(PY_VERSION_HEX)); svnversion_init(); 
0
source

Source: https://habr.com/ru/post/1413041/


All Articles