Debian

dpkg 在安裝 python 包時返回錯誤(Debian)

  • November 4, 2020

在嘗試安裝 pdfshuffler(來自 Debian repo)後,出現了與依賴問題相關的錯誤。似乎需要 python-pypdf2 包,所以我嘗試安裝它,但我得到了相同的錯誤消息。在查找了類似的問題後,我嘗試了 apt-get clean、install-f、autoremove 等,但它沒有用,並且處理過程中遇到的錯誤列表不斷增加。我留下了 apt-get upgrade 後得到的錯誤:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
 mendeleydesktop
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
15 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 python-crypto (2.6.1-7) ...
Traceback (most recent call last):
 File "/usr/bin/pycompile", line 27, in <module>
   import optparse
 File "/usr/lib/python2.7/optparse.py", line 1557
   print(self.get_usage(), file=file)
                               ^
SyntaxError: invalid syntax
dpkg: error processing package python-crypto (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up python-wheel (0.29.0-2) ...
Traceback (most recent call last):
 File "/usr/bin/pycompile", line 27, in <module>
   import optparse

 File "/usr/lib/python2.7/optparse.py", line 1557
   print(self.get_usage(), file=file)
                               ^
SyntaxError: invalid syntax
dpkg: error processing package python-wheel (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up python-roman (2.0.0-2) ...
Traceback (most recent call last):
 File "/usr/bin/pycompile", line 27, in <module>
   import optparse
 File "/usr/lib/python2.7/optparse.py", line 1557
   print(self.get_usage(), file=file)
                               ^
SyntaxError: invalid syntax
dpkg: error processing package python-roman (--configure):                                                                                                                                                     
subprocess installed post-installation script returned error exit status 1                                                                                                                                    
Setting up python-pypdf2 (1.26.0-2) ...                                                                                                                                                                        
Traceback (most recent call last):                                                                                                                                                                             
 File "/usr/bin/pycompile", line 27, in <module>                                                                                                                                                              
   import optparse                                                                                                                                                                                            
 File "/usr/lib/python2.7/optparse.py", line 1557                                                                                                                                                             
   print(self.get_usage(), file=file)                                                                                                                                                                         
                               ^                                                                                                                                                                              
SyntaxError: invalid syntax                                                                                                                                                                                    
dpkg: error processing package python-pypdf2 (--configure):                                                                                                                                                    
subprocess installed post-installation script returned error exit status 1                                                                                                                                    
dpkg: dependency problems prevent configuration of python-keyrings.alt:                                                                                                                                        
python-keyrings.alt depends on python-crypto; however:                                                                                                                                                        
 Package python-crypto is not configured yet.                                                                                                                                                                 

dpkg: error processing package python-keyrings.alt (--configure):                                                                                                                                              
dependency problems - leaving unconfigured                                                                                                                                                                    
Setting up python-gi (3.22.0-2) ...                                                                                                                                                                            
Traceback (most recent call last):                                                                                                                                                                             
 File "/usr/bin/pycompile", line 27, in <module>                                                                                                                                                              
   import optparse
 File "/usr/lib/python2.7/optparse.py", line 1557
   print(self.get_usage(), file=file)
                               ^
SyntaxError: invalid syntax
dpkg: error processing package python-gi (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up python-epydoc (3.0.1+dfsg-14) ...
Traceback (most recent call last):
 File "/usr/bin/pycompile", line 27, in <module>
   import optparse
 File "/usr/lib/python2.7/optparse.py", line 1557
   print(self.get_usage(), file=file)
                               ^
SyntaxError: invalid syntax
dpkg: error processing package python-epydoc (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of pdfshuffler:
pdfshuffler depends on python-pypdf2 | python-pypdf (>= 1.10); however:
 Package python-pypdf2 is not configured yet.
 Package python-pypdf is not installed.

dpkg: error processing package pdfshuffler (--configure):
dependency problems - leaving unconfigured
Setting up python-dbus (1.2.4-1+b1) ...
Remove stale byte-compiled files...
Traceback (most recent call last):
 File "/usr/bin/pycompile", line 27, in <module>
   import optparse
 File "/usr/lib/python2.7/optparse.py", line 1557
   print(self.get_usage(), file=file)
                               ^
SyntaxError: invalid syntax
dpkg: error processing package python-dbus (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up python-xdg (0.25-4) ...
Traceback (most recent call last):
 File "/usr/bin/pycompile", line 27, in <module>
   import optparse
 File "/usr/lib/python2.7/optparse.py", line 1557
   print(self.get_usage(), file=file)
                               ^
SyntaxError: invalid syntax
dpkg: error processing package python-xdg (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of python-secretstorage:
python-secretstorage depends on python-dbus; however:
 Package python-dbus is not configured yet.

dpkg: error processing package python-secretstorage (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-docutils:
python-docutils depends on python-roman; however:
 Package python-roman is not configured yet.

dpkg: error processing package python-docutils (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-keyring:
python-keyring depends on python-dbus; however:
 Package python-dbus is not configured yet.
python-keyring depends on python-secretstorage; however:
 Package python-secretstorage is not configured yet.

dpkg: error processing package python-keyring (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-gobject:
python-gobject depends on python-gi (>= 3.22.0-2); however:
 Package python-gi is not configured yet.

dpkg: error processing package python-gobject (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-poppler:
python-poppler depends on python-gobject (>= 2.10.1); however:
 Package python-gobject is not configured yet.

dpkg: error processing package python-poppler (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
python-crypto
python-wheel
python-roman
python-pypdf2
python-keyrings.alt
python-gi
python-epydoc
pdfshuffler
python-dbus
python-xdg
python-secretstorage
python-docutils
python-keyring
python-gobject
python-poppler
E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo apt-get install當我嘗試使用任何 python-PACKAGE時,它會得到類似的結果。我還嘗試編輯 /var/lib/dpkg/status 文件,刪除未正確安裝或配置的 python 包的條目,但沒有幫助(嘗試重新安裝或刪除這些包時再次出現相同的問題)。

任何的想法?

謝謝!

(系統:Debian Stretch w/KDE Plasma。I7 8500U 16Gb)

根據Filipe Branderburger的評論,我查找了 optparse.py 中的錯誤:

eric@debian:~$ dpkg -S /usr/lib/python2.7/optparse.py
libpython2.7-minimal:amd64: /usr/lib/python2.7/optparse.py
eric@debian:~$ dpkg -V libpython2.7-minimal
??5??????   /usr/lib/python2.7/optparse.py
eric@debian:~$ ls -l /usr/lib/python2.7/optparse.py
-rw-r--r-- 1 eric eric 60337 Mar 20 00:01 /usr/lib/python2.7/optparse.py
eric@debian:~$ readlink -f /usr/lib/python2.7/optparse.py
/usr/lib/python2.7/optparse.py

是不是表示md5sum驗證失敗了?

因此,您的 Python 2.7 安裝中的文件似乎optparse.py已損壞。更具體地說,它似乎已被optparse.pyPython 3 的副本覆蓋和替換。

的輸出dpkg -V顯示了檢查所有者、組、模式等的許多欄位。5輸出中的 表示系統中文件的 MD5 校驗和與包清單中的不匹配。(也就是說,安裝包後內容已經被修改過。)

不太確定如何找出可能導致這種情況的原因…如果您以 root 身份安裝了 Python 模組,使用的不是您的 OS 包分發,那可以解釋它…也許如果您使用pip? 雖然pip通常擅長將 Python 2 和 Python 3 模組分開……另外,我不明白為什麼它會optparse.py特別觸及……

在任何情況下,要解決此問題,您可以要求 apt-get 重新安裝軟體包,這應該可以修復損壞:

$ sudo apt-get install --reinstall libpython2.7-minimal

引用自:https://unix.stackexchange.com/questions/437788