1

After trying to install pdfshuffler (from Debian repo) an error related to dependency problems appeared. It seemed that python-pypdf2 package was needed, so I tried to install it but I get to the same error message. After looking up for similar problems, I tried with apt-get clean, install-f, autoremove, etc but it was useless and the list of errors encountered while processing keeps growing. I leave the error I get after 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)

It get something similar when I try sudo apt-get install with any python-PACKAGE. I also tried editing /var/lib/dpkg/status file, deleting the entries of not properly installed or configured python packages, but it didn't help (the same problem reappeared when trying to reinstall or removed these packages).

Any idea?

Thank you!

(System: Debian Stretch w/KDE Plasma. I7 8500U 16Gb)

Following Filipe Branderburger's comments, I looked up for errors in 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

Does it means that the md5sum verification has failed?

0

So it looks like file optparse.py from your Python 2.7 installation got corrupted. More specifically, it seems to have been overwritten and replaced by a copy of optparse.py from Python 3.

The output of dpkg -V shows many fields checking owner, group, mode, etc. The 5 in the output indicates that the MD5 checksum of the file in the system doesn't match the one in the package manifest. (In other words, the contents have been modified after the package was installed.)

Not really sure how you could find out what might have caused that... If you have installed Python modules, as root, using something other than your O.S. package distribution, that could explain it... Perhaps if you installed something using pip? Though pip is usually good at keeping Python 2 and Python 3 modules separate... Also, I don't see why it would touch optparse.py specifically...

In any case, to fix this problem, you could ask apt-get to reinstall the package, which should fix the corruption:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.