Ubuntu
管理包時出現“ImportError: No module named _struct”錯誤
我正在執行基本 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)
所以這是不行的。
我找到了一種通過簡單地刪除
idle-python2.7
包來解決這個問題的方法:sudo apt-get remove idle-python2.7
如此處所述。
搜尋這個出現了一些可以嘗試的東西。
- 重新安裝python
在手動建構和安裝 python 2.6 後找到了這個連結:Broken python (2.7)。建議是像這樣重新安裝:
$ sudo apt-get --reinstall install python python-support
- 確保軟體更新應用程序已啟用網際網路
找到這個連結:更多包依賴問題,我總是在全新安裝後遇到很多問題。
我進入更新管理器/設置 Ubuntu 軟體選項卡並重新啟用所有可從 Internet 按鈕下載的內容。