python 和套件管理器壞了

python 和套件管理器壞了

將 Ubuntu 從 升級到 後15.0416.04pythonpackage manager損壞了。

運行時apt-get update我收到訊息use apt-get -f install,但運行此命令時出現以下錯誤:

Get:1 http://at.archive.ubuntu.com/ubuntu xenial/main amd64 python amd64 2.7.11-1 [137 kB]
Fetched 137 kB in 0s (1.700 kB/s)
Setting up python-minimal (2.7.11-1) ...
Traceback (most recent call last):
   File "/usr/local/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"  __main__", fname, loader, pkg_name)
File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
 exec code in run_globals
File "/usr/local/lib/python2.7/compileall.py", line 16, in <module>
 import struct
File "/usr/local/lib/python2.7/struct.py", line 1, in <module>
 from _struct import *
ImportError: No module named _struct 
dpkg: error processing package python-minimal (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
  python-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

我還嘗試了其他帖子中提出的解決方案:

sudo dpkg-reconfigure python-minimal
/usr/sbin/dpkg-reconfigure: python-minimal is broken or not fully installed

sudo dpkg --configure -a
Setting up python-minimal (2.7.11-1) ...
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/runpy.py", line 162, in _run_module_as_main
  "__main__", fname, loader, pkg_name)
  File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
   exec code in run_globals
  File "/usr/local/lib/python2.7/compileall.py", line 16, in <module>
   import struct
  File "/usr/local/lib/python2.7/struct.py", line 1, in <module>
   from _struct import *
  ImportError: No module named _struct
  dpkg: error processing package python-minimal (--configure):
  subprocess installed post-installation script returned error exit status 1
  Errors were encountered while processing:
    python-minimal

reinstall python-minimal沒用。

另外,當嘗試跑步時apt-get remove|autoremove,我也得到了相同的結果python error

更新1

我剛剛嘗試過:

apt-get download python-minimal
sudo dpkg --install ./python-minimal_2.7.11-1_amd64.deb

但我仍然遇到同樣的錯誤

更新2

我設法python通過這樣做來刪除損壞的包:

apt-get download synaptic
sudo dpkg --install ./synaptic...

然後我使用 刪除了軟體包synaptic,但問題是現在刪除它們後,每次我想安裝某些東西時,軟體包管理器都會自動嘗試安裝python2.7-11python-minimal-2.7-11,但他沒有成功,我再次收到錯誤。

答案1

在升級到 之前Ubuntu 16.04,我已經python2.7.5安裝了,我假設在升級過程中,Ubuntu嘗試python從升級2.7.52.7.11,但失敗了,所以我最終的文件python2.7.5仍然在筆記型電腦上並python2.7.11部分安裝。

我透過這樣做解決了我的錯誤:

  • 刪除了部分安裝的部分,如我的問題python2.7.11所述UPDATE2
  • 刪除了資料夾python2.7.5

    sudo rm -rf /usr/lib/python2.7/
    
  • 重新安裝python2.7->python2.7.11及其相依性已正確安裝
  • 完畢!現在一切正常了!

相關內容