系统相关
首页 > 系统相关> > ubuntu – 管理包时出现’ImportError:没有名为_struct的模块’错误

ubuntu – 管理包时出现’ImportError:没有名为_struct的模块’错误

作者:互联网

我正在运行基本操作系统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)

所以这是不行的.

解决方法:

搜索这个问题需要考虑几个方面.

>重新安装python

找到此链接:Broken python (2.7) after manually building and installing python 2.6.建议重新安装如下:

$sudo apt-get --reinstall install python python-support

>确保软件更新应用程序已启用Internet

找到此链接:more package dependency problems, i always get loads of problems after a fresh install.

face palm I went into update manager/settings Ubuntu software tab and re-enabled all downloadable from internet buttons.

标签:dpkg,python,ubuntu,apt,elementary-os
来源: https://codeday.me/bug/20190810/1637650.html