AttributeError:“module”对象没有属性“pydebug”

2024-06-01 02:04:59 发布

您现在位置:Python中文网/ 问答频道 /正文

当尝试运行python脚本时,我得到错误AttributeError: 'module' object has no attribute 'pydebug'。我正在使用Python2.6。

完全错误:

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'

Tags: nopy脚本objectlib错误lineattribute
3条回答

当我在一个Ubuntu系统上运行gdb时收到这个错误,在这个Ubuntu系统上已经安装了Python的另一个版本,并且链接器首选它。您可以通过使用ldd询问哪些库gdb正在使用,来验证这种情况是否发生:

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

您可以看到,运行在/usr/local/lib中的非品牌版本的Python正在为libpython提供gdb而不是/usr/lib中的官方Ubuntu Python,这是导致错误的原因-无论/usr/local中的非品牌Python的编译方式与Ubuntu Python的编译方式不同,因此,对gdb的期望是令人失望的。

解决方案是使用环境来控制链接器的行为,并使其更喜欢系统libpython。为了更好地衡量,我还将PATH重置为完全标准的值。我发现这有效:

PATH=/bin:/usr/bin LD_LIBRARY_PATH=/usr/lib gdb ...

当我试图在我自己构建的python上运行Ubuntu 12.04.1系统gdb时遇到了这个问题。我希望Ubuntu已经在gdb系统中构建了一些钩子,这样它就使用了Python的调试版本;但是钩子并没有锁定到我自己Python中的任何东西。我通过建立自己的gdb并运行它来解决这个问题。

下面是命令行和完整的回溯:

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'

所以它似乎在寻找错误的python(在/usr/lib中),尽管我已经告诉系统不要这样做:

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

我认为无论您尝试运行什么,都希望与python的特殊调试构建一起使用。sys.pydebug通常在sys模块的标准版本中找不到,我相信如果您构建了一个调试python,它就会出现:

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

这也可能是Debian/Ubuntu发行版正在使用的特定构建的一部分。

相关问题 更多 >