我正在运行Elementary OS 0.2(基于Ubuntu 12.04),从今天开始,我在尝试安装/升级软件包时看到一个奇怪的错误。刚才我做了一个例子:
sudo apt-get update
效果很好,然后是:
sudo apt-get upgrade
尝试返回这个:
Setting up idle-python2.7 (2.7.3-0ubuntu3.5) ...
Traceback (most recent call last):
File "/usr/lib/python2.7/compileall.py", line 16, in <module>
import struct
File "/usr/lib/python2.7/struct.py", line 1, in <module>
from _struct import *
ImportError: No module named _struct
dpkg: error processing idle-python2.7 (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
idle-python2.7
E: Sub-process /usr/bin/dpkg returned an error code (1)
到底是怎么回事?显然这与包有关,python
但我仍然可以python
毫无问题地运行脚本。我怎样才能解决这个问题?
添加
按照我尝试过的答案中给出的建议:
sudo apt-get --reinstall install python python-support
这返回了:
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 2 reinstalled, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/192 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 864980 files and directories currently installed.)
Preparing to replace python 2.7.3-0ubuntu2.2 (using .../python_2.7.3-0ubuntu2.2_i386.deb) ...
Unpacking replacement python ...
Preparing to replace python-support 1.0.14ubuntu2 (using .../python-support_1.0.14ubuntu2_all.deb) ...
Unpacking replacement python-support ...
Processing triggers for man-db ...
Processing triggers for doc-base ...
Processing 1 changed doc-base file...
Registering documents with scrollkeeper...
Setting up idle-python2.7 (2.7.3-0ubuntu3.5) ...
Traceback (most recent call last):
File "/usr/lib/python2.7/compileall.py", line 16, in <module>
import struct
File "/usr/lib/python2.7/struct.py", line 1, in <module>
from _struct import *
ImportError: No module named _struct
dpkg: error processing idle-python2.7 (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up python (2.7.3-0ubuntu2.2) ...
Setting up python-support (1.0.14ubuntu2) ...
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site.py", line 548, in <module>
main()
File "/usr/local/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/usr/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/usr/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Errors were encountered while processing:
idle-python2.7
E: Sub-process /usr/bin/dpkg returned an error code (1)
所以这是不行的。
答案1
搜索此内容会出现一些需要尝试的事情。
重新安装python
找到这个链接:手动构建和安装 python 2.6 后损坏的 python (2.7)。建议是像这样重新安装:
$ sudo apt-get --reinstall install python python-support
确保软件更新应用程序已启用互联网
找到这个链接:更多包依赖性问题,全新安装后我总是遇到很多问题。
脸掌我进入更新管理器/设置 Ubuntu 软件选项卡并重新启用所有可从互联网下载的按钮。
答案2
答案3
答案很简单。您的系统配置错误。您在本地安装了基本 Python 包。这是一个禁忌。您应该从发行版存储库安装基本二进制 Python 包。特别是,您的 Python 安装正在查找lib/python2.7/site.py
和lib/python2.7/sysconfig.py
中的文件/usr/local
,但这些文件是基本 Python 包的一部分python2.7-minimal
,或者可能是 libpython2.7-minimal
,具体取决于您的发行版对应的 Debian/Ubuntu 版本。
不管怎样,解决办法很简单。删除本地安装的基本 Python 包,然后从您的发行版安装基本 Python 包。如果您的发行版中没有该软件,然后在本地安装它。如果您不使用发行版的软件包,那么使用发行版实际上没有多大意义。
什么是
apt-cache policy python2.7-minimal libpython2.7-minimal python2.7
说?其中两个应该安装在您的系统上。