1

I'm not an advanced user of Ubuntu, and I have a really big issue. When I run:

sudo apt-get update && sudo apt-get upgrade

I get the following output:

Hit:1 http://pl.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://pl.archive.ubuntu.com/ubuntu bionic-updates InRelease                  
Hit:3 http://pl.archive.ubuntu.com/ubuntu bionic-backports InRelease                
Hit:4 http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu bionic InRelease         
Ign:5 http://download.opensuse.org/repositories/home:/manuelschneid3r/xUbuntu_18.04  InRelease
Hit:6 http://download.opensuse.org/repositories/home:/manuelschneid3r/xUbuntu_18.04  Release
Hit:7 http://ppa.launchpad.net/team-xbmc/ppa/ubuntu bionic InRelease                
Hit:8 https://dl.winehq.org/wine-builds/ubuntu bionic InRelease                     
Hit:9 http://security.ubuntu.com/ubuntu bionic-security InRelease                   
Hit:11 https://packagecloud.io/slacktechnologies/slack/debian jessie InRelease      
Reading package lists... Done                                  
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  linux-generic-hwe-18.04 linux-headers-generic-hwe-18.04
  linux-image-generic-hwe-18.04
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
6 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 python3-apt (1.6.4) ...
/bin/sh: 1: /usr/bin/python3.6: Permission denied
Traceback (most recent call last):
  File "/usr/bin/py3compile", line 290, in <module>
    main()
  File "/usr/bin/py3compile", line 270, in main
    options.force, options.optimize, e_patterns)
  File "/usr/bin/py3compile", line 156, in compile
    cfn = interpreter.cache_file(fn, version)
  File "/usr/share/python3/debpython/interpreter.py", line 212, in cache_file
    (fname[:-3], self.magic_tag(version), last_char))
  File "/usr/share/python3/debpython/interpreter.py", line 246, in magic_tag
    return self._execute('import imp; print(imp.get_tag())', version)
  File "/usr/share/python3/debpython/interpreter.py", line 359, in _execute
    raise Exception('{} failed with status code {}'.format(command, output['returncode']))
Exception: python3.6 -c 'import imp; print(imp.get_tag())' failed with status code 126
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was: Traceback (most recent call last): File "/usr/bin/py3compile", line 290, in <module> main() File "/usr/bin/py3compile", line 270, in main options.force, options.optimize, e_patterns) File "/usr/bin/py3compile", line 156, in compile cfn = interpreter.cache_file(fn, version) File "/usr/share/python3/debpython/interpreter.py", line 212, in cache_file (fname[:-3], self.magic_tag(version), last_char)) File "/usr/share/python3/debpython/interpreter.py", line 246, in magic_tag return self._execute('import imp; print(imp.get_tag())', version) File "/usr/share/python3/debpython/interpreter.py", line 359, in _execute raise Exception('{} failed with status code {}'.format(command, output['returncode'])) Exception: python3.6 -c 'import imp; print(imp.get_tag())' failed with status code 126 dpkg: error processing package python3-apt (--configure): installed python3-apt package post-installation script subprocess returned error exit status 1 Setting up usb-creator-common (0.3.5ubuntu18.04.2) ... /bin/sh: 1: /usr/bin/python3.6: Permission denied Traceback (most recent call last): File "/usr/bin/py3compile", line 290, in <module> main() File "/usr/bin/py3compile", line 270, in main options.force, options.optimize, e_patterns) File "/usr/bin/py3compile", line 156, in compile cfn = interpreter.cache_file(fn, version) File "/usr/share/python3/debpython/interpreter.py", line 212, in cache_file (fname[:-3], self.magic_tag(version), last_char)) File "/usr/share/python3/debpython/interpreter.py", line 246, in magic_tag return self._execute('import imp; print(imp.get_tag())', version) File "/usr/share/python3/debpython/interpreter.py", line 359, in _execute raise Exception('{} failed with status code {}'.format(command, output['returncode'])) Exception: python3.6 -c 'import imp; print(imp.get_tag())' failed with status code 126 Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in <module> from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module> import apport.fileutils File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module> from apport.packaging_impl import impl as packaging File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module> import apt File "/usr/lib/python3/dist-packages/apt/init.py", line 23, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg'

Original exception was: Traceback (most recent call last): File "/usr/bin/py3compile", line 290, in <module> main() File "/usr/bin/py3compile", line 270, in main options.force, options.optimize, e_patterns) File "/usr/bin/py3compile", line 156, in compile cfn = interpreter.cache_file(fn, version) File "/usr/share/python3/debpython/interpreter.py", line 212, in cache_file (fname[:-3], self.magic_tag(version), last_char)) File "/usr/share/python3/debpython/interpreter.py", line 246, in magic_tag return self._execute('import imp; print(imp.get_tag())', version) File "/usr/share/python3/debpython/interpreter.py", line 359, in _execute raise Exception('{} failed with status code {}'.format(command, output['returncode'])) Exception: python3.6 -c 'import imp; print(imp.get_tag())' failed with status code 126 dpkg: error processing package usb-creator-common (--configure): installed usb-creator-common package post-installation script subprocess returned error exit status 1 dpkg: dependency problems prevent configuration of usb-creator-gtk: usb-creator-gtk depends on usb-creator-common (= 0.3.5ubuntu18.04.2); however: Package usb-creator-common is not configured yet.

dpkg: error processing package usb-creator-gtk (--configure): dependency problems - leaving unconfigured No apport report written because the error message indicates its a followup error from a previous failure. dpkg: dependency problems prevent configuration of python3-apport: python3-apport depends on python3-apt (>= 0.7.9); however: Package python3-apt is not configured yet.

dpkg: error processing package python3-apport (--configure): dependency problems - leaving unconfigured dpkg: dependency problems prevent configuration of apport: apport depends on python3-apport (>= 2.20.9-0ubuntu7.7); however: Package python3-apport is not configured yet.

dpkg: error processing package apport (--configure): dependency problems - leaving unconfigured No apport report written because MaxReports is reached already No apport report written because MaxReports is reached already Setting up python-apt (1.6.4) ... /var/lib/dpkg/info/python-apt.postinst: 6: /var/lib/dpkg/info/python-apt.postinst: pycompile: Permission denied dpkg: error processing package python-apt (--configure): installed python-apt package post-installation script subprocess returned error exit status 126 No apport report written because MaxReports is reached already Errors were encountered while processing: python3-apt usb-creator-common usb-creator-gtk python3-apport apport python-apt E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried many different solutions from this site, but nothing works for me. Something went wrong when I tried to update Python from 3.6 to 3.7. I'm sorry if I am talking about a topic that already exists, but I can't find any solution that works with all these errors combined. I can add any command output you want, but, as I said, I'm not a very advanced user.


@nobody

Input:

sudo dpkg -i python3-apt_1.6.0_amd64.deb python-apt_1.6.0_amd64.deb

Output:

dpkg: warning: downgrading python3-apt from 1.6.4 to 1.6.0
(Reading database ... 182414 files and directories currently installed.)
Preparing to unpack python3-apt_1.6.0_amd64.deb ...
Unpacking python3-apt (1.6.0) over (1.6.4) ...
Preparing to unpack python-apt_1.6.0_amd64.deb ...
/var/lib/dpkg/info/python-apt.prerm: 6: /var/lib/dpkg/info/python-apt.prerm: pyclean: Permission denied
dpkg: error processing archive python-apt_1.6.0_amd64.deb (--install):
 installed python-apt package pre-removal script subprocess returned error exit status 126
/var/lib/dpkg/info/python-apt.postinst: 6: /var/lib/dpkg/info/python-apt.postinst: pycompile: Permission denied
dpkg: error while cleaning up:
 installed python-apt package post-installation script subprocess returned error exit status 126
Setting up python3-apt (1.6.0) ...
/bin/sh: 1: /usr/bin/python3.6: Permission denied
Traceback (most recent call last):
  File "/usr/bin/py3compile", line 290, in <module>
    main()
  File "/usr/bin/py3compile", line 270, in main
    options.force, options.optimize, e_patterns)
  File "/usr/bin/py3compile", line 156, in compile
    cfn = interpreter.cache_file(fn, version)
  File "/usr/share/python3/debpython/interpreter.py", line 212, in cache_file
    (fname[:-3], self.magic_tag(version), last_char))
  File "/usr/share/python3/debpython/interpreter.py", line 246, in magic_tag
    return self._execute('import imp; print(imp.get_tag())', version)
  File "/usr/share/python3/debpython/interpreter.py", line 359, in _execute
    raise Exception('{} failed with status code {}'.format(command, output['returncode']))
Exception: python3.6 -c 'import imp; print(imp.get_tag())' failed with status code 126
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was: Traceback (most recent call last): File "/usr/bin/py3compile", line 290, in <module> main() File "/usr/bin/py3compile", line 270, in main options.force, options.optimize, e_patterns) File "/usr/bin/py3compile", line 156, in compile cfn = interpreter.cache_file(fn, version) File "/usr/share/python3/debpython/interpreter.py", line 212, in cache_file (fname[:-3], self.magic_tag(version), last_char)) File "/usr/share/python3/debpython/interpreter.py", line 246, in magic_tag return self._execute('import imp; print(imp.get_tag())', version) File "/usr/share/python3/debpython/interpreter.py", line 359, in _execute raise Exception('{} failed with status code {}'.format(command, output['returncode'])) Exception: python3.6 -c 'import imp; print(imp.get_tag())' failed with status code 126 dpkg: error processing package python3-apt (--install): installed python3-apt package post-installation script subprocess returned error exit status 1 Errors were encountered while processing: python-apt_1.6.0_amd64.deb python3-apt

I hope that system reinstallation isn't one and only way to fix it

Thomas Ward
  • 78,878
bbaker
  • 11

2 Answers2

0

Internal Error sounds not good.

wget -c http://mirrors.kernel.org/ubuntu/pool/main/p/python-apt/python3-apt_1.6.0_amd64.deb

and

wget -c http://mirrors.kernel.org/ubuntu/pool/main/p/python-apt/python-apt_1.6.0_amd64.deb

Install the 2 package with sudo dpkg -i python3-apt_1.6.0_amd64.deb python-apt_1.6.0_amd64.deb

If this work sudo dpkg --configure -a && sudo apt -f install

Then upgdrade your system

sudo apt full-upgrade
nobody
  • 5,792
0

I had the same issue on Ubuntu 22.04 with python 3.10.4. The following command resolved the issue:

sudo apt --fix-broken install