3

我不小心替换了位于 /usr/local/bin/ 的 python 二进制文件。从那以后,我无法运行任何 python 脚本,甚至无法运行 python 的交互模式。

$ python
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 558, in get_config_var
    return get_config_vars().get(name)
  File "/usr/lib/python2.7/sysconfig.py", line 457, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/lib/python2.7/sysconfig.py", line 303, in _init_posix
    makefile = _get_makefile_filename()
  File "/usr/lib/python2.7/sysconfig.py", line 297, 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'

我已经看到与“AttributeError: 'module' object has no attribute 'pydebug'”错误相关的问题,但我仍然不知道如何解决这个问题。

当我尝试重新安装时出现同样的错误:

$ sudo apt-get install python2.7-minimal
[sudo] password for : 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python2.7-minimal is already the newest version.
The following packages were automatically installed and are no longer required:
  libgsasl7 libmailutils2 libntlm0
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 402 not upgraded.
4 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? Y
Setting up python2.7-minimal (2.7.1-5ubuntu2.2) ...
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 558, in get_config_var
    return get_config_vars().get(name)
  File "/usr/lib/python2.7/sysconfig.py", line 457, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/lib/python2.7/sysconfig.py", line 303, in _init_posix
    makefile = _get_makefile_filename()
  File "/usr/lib/python2.7/sysconfig.py", line 297, 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'
dpkg: error processing python2.7-minimal (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of python2.7:
 python2.7 depends on python2.7-minimal (= 2.7.1-5ubuntu2.2); however:
  Package python2.7-minimal is not configured yet.
dpkg: error processing python2.7 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of libpython2.7:
 libpython2.7 depends on python2.7 (= 2.7.1-5ubuntu2.2); however:
  Package python2.7 is not configured yet.
dpkg: error processing libpython2.7 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python2.7-dev:
 python2.7-dev depends on python2.7 (= 2.7.1-5ubuntu2.2); however:
  Package python2.7 is not configured yet.
 python2.7-dev depeNo apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                                             No apport report written because the error message indicates its a followup error from a previous failure.
                                                                          No apport report written because MaxReports is reached already
                                                                                                                                        nds on libpython2.7 (= 2.7.1-5ubuntu2.2); however:
  Package libpython2.7 is not configured yet.
dpkg: error processing python2.7-dev (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python2.7-minimal
 python2.7
 libpython2.7
 python2.7-dev
E: Sub-process /usr/bin/dpkg returned an error code (1)
4

3 回答 3

4

问题是您正在击中/usr/local/bin/python而不是/usr/bin/python.

您可以通过运行类似...的方式将其移开

mv /usr/local/bin/python /usr/local/bin/python.old

...以 root 身份,或者如果您确定不需要它,那么只需使用...删除它

rm /usr/local/bin/python

如果 bash 仍然尝试运行/usr/local/bin/python,并且运行type python打印...

python is hashed (/usr/local/bin/python)

...然后hash -r清除哈希表。

/usr/bin/python复制到不是一个好主意/usr/local/bin/python,否则下次用 更新python 时可能会出现问题apt-get upgrade,即它会更新/usr/bin/python,但/usr/local/bin/python默认情况下仍会运行。

于 2013-04-29T16:42:56.007 回答
2

看起来这与专门用于调试的 Python 构建有关。

我建议您使用 apt-get 重新安装 Python:

sudo apt-get install --reinstall python2.7

你的问题似乎和这个 SO question一样sys.pydebug

于 2013-04-29T16:38:01.350 回答
0

你必须重新安装。这是一个更好的解决方案。这是我在 Ubuntu 上最喜欢的终端安装。尝试: 安装 Python 和cherrypy

你看看这个问题的答案

安装python

于 2013-04-29T16:24:55.073 回答