Python 3.8.x problems in 20.04

5,161

Solution 1

I responded to your previous post but it appears it being locked caused some issues.

As I mentioned in my original post, you can manually extract the relevant .deb files and rebuild a cobbled together Python to bootstrap yourself. It does appear that https://packages.ubuntu.com/focal/python3 does not have any mirrors listed for arm64 but, after some brief searching, I found https://ubuntu.pkgs.org/20.04/ubuntu-main-arm64/python3_3.8.2-0ubuntu2_arm64.deb.html which gives you all the package names and then points you to http://ports.ubuntu.com/pool/main/p/python3.8/ for download (this mirror has all the arm64 packages). You'll have to start at the "python3" package and manually drill down all the dependencies to grab them all. It looks like py3compile and py3clean are both in python3-minimal package

Secondly, and I say this having made many mistakes myself, there are innumerable things people can do with sudo that can render a system inoperable and there are no realistic safeguards. Should sudo rm require a warning/confirmation every time? How about sudo chmod? For every post about someone breaking their system with Python problems, I can probably point to as many where people did something bad with permissions or deleted the wrong file.

Solution 2

I will quote from experience - if you attempt to upgrade Python from source in your system, you will torch your system in a unfixable way. The fastest and most easiest solution in these cases is to reinstall your system or restore from a known good backup image and DO NOT attempt to upgrade Python from source.

The "reinstall" answer applies to all OS versions, not just ISO installs.

Restoring system python from your 'backup image' is going to be pain, so you may as well just do a full system restore from your backup. Or reinstall from scratch.


As for getting Newer python for your own needs, you may want to look into using PyEnv which is a project/tool that lets you have multiple Python versions installed in User Space without affecting your system Python and thereby doesn't break your system python. Because updating System level python will leave you with a broken system in many cases.

Share:
5,161
WhatOnEarthOrOutsideIt
Author by

WhatOnEarthOrOutsideIt

Updated on September 18, 2022

Comments

  • WhatOnEarthOrOutsideIt
    WhatOnEarthOrOutsideIt almost 2 years

    I was already on my way to reverting to a backup image of my MicroSD that was ~1.5 week old until after writing it to a brand new SanDisk Micro SD card, the ext4 filesystem gave a bunch of inode errors during boot time, everything in the OS was more or less totally broken and fsck gave basically an insane list of things that were broken on a filesystem level. It's a brand new Sandisk Micro SD card, but apparently during the backup process, data corruption slipped in through the back door.

    I'm running Ubuntu 20.04 on a Raspberry Pi 4B, which means that it's running on arm64 architecture, so suggestions to download the .deb packages straight from kernel.org, or to install i.e. python3-minimal doesn't work, since there aren't any installation candidates for ARM64.

    • Solutions pointing to .deb and other installation packages that simply do not exist for arm64 architecture at all.

    • There was also plenty of outdated or downright bad advice altogether -- also, none of the system restore methods described in either the manuals or within Ubuntu's user community (boot CD on a Raspberry Pi?) don't apply to 20.04 on the Raspberry Pi 4B, at least not yet.

    My install is still staggering along, but the apt/dpkg update system remains pretty much broken no matter what I try. I have unsuccessfully tried downloading the .deb packages and installing them separately.

    As for this moment; Py3compile and Pyclean are not found anywhere and those two are the main culprits in dpkg/apt not working, so this answer doesn't work.

    $ sudo apt install python3-all
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    python3-all is already the newest version (3.8.2-0ubuntu2).
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    4 not fully installed or removed.
    Need to get 0 B/129 kB of archives.
    After this operation, 0 B of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Setting up pychess (0.12.2-1build1) ...
    /var/lib/dpkg/info/pychess.postinst: 6: pycompile: not found
    dpkg: error processing package pychess (--configure):
     installed pychess package post-installation script subprocess returned error ex                                   it status 127
    dpkg: error processing package python-pkg-resources (--configure):
     package is in a very bad inconsistent state; you should
     reinstall it before attempting configuration
    Setting up gir1.2-dee-1.0 (1.2.7+17.10.20170616-4ubuntu6) ...
    /var/lib/dpkg/info/gir1.2-dee-1.0.postinst: 6: pycompile: not found
    dpkg: error processing package gir1.2-dee-1.0 (--configure):
     installed gir1.2-dee-1.0 package post-installation script subprocess returned e                                   rror exit status 127
    Setting up python3-minimal (3.8.2-0ubuntu2) ...
    Traceback (most recent call last):
      File "/usr/bin/py3compile", line 28, in <module>
        import struct
      File "/usr/lib/python3.8/struct.py", line 13, in <module>
        from _struct import *
    ModuleNotFoundError: No module named '_struct'
    dpkg: error processing package python3-minimal (--configure):
     installed python3-minimal package post-installation script subprocess returned                                    error exit status 1
    No apport report written because MaxReports is reached already
                                                                  Errors were encoun                                   tered while processing:
     pychess
     python-pkg-resources
     gir1.2-dee-1.0
     python3-minimal
    needrestart is being skipped since dpkg has failed
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    
    • Reinstalling with sudo apt install --reinstall -f python3-all does not help either.
      $ sudo apt install --reinstall -f python3-all
      Reading package lists... Done
      Building dependency tree
      Reading state information... Done
      0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
      4 not fully installed or removed.
      Need to get 0 B/131 kB of archives.
      After this operation, 0 B of additional disk space will be used.
      (Reading database ... 1052975 files and directories currently installed.)
      Preparing to unpack .../python3-all_3.8.2-0ubuntu2_arm64.deb ...
      Unpacking python3-all (3.8.2-0ubuntu2) over (3.8.2-0ubuntu2) ...
      Setting up pychess (0.12.2-1build1) ...
      /var/lib/dpkg/info/pychess.postinst: 6: pycompile: not found
      dpkg: error processing package pychess (--configure):
       installed pychess package post-installation script subprocess returned error exit status 127
      dpkg: error processing package python-pkg-resources (--configure):
       package is in a very bad inconsistent state; you should
       reinstall it before attempting configuration
      Setting up python3-all (3.8.2-0ubuntu2) ...
      Setting up gir1.2-dee-1.0 (1.2.7+17.10.20170616-4ubuntu6) ...
      /var/lib/dpkg/info/gir1.2-dee-1.0.postinst: 6: pycompile: not found
      dpkg: error processing package gir1.2-dee-1.0 (--configure):
       installed gir1.2-dee-1.0 package post-installation script subprocess returned error exit status 127
      Setting up python3-minimal (3.8.2-0ubuntu2) ...
      Traceback (most recent call last):
        File "/usr/bin/py3compile", line 28, in <module>
          import struct
        File "/usr/lib/python3.8/struct.py", line 13, in <module>
          from _struct import *
      ModuleNotFoundError: No module named '_struct'
      dpkg: error processing package python3-minimal (--configure):
       installed python3-minimal package post-installation script subprocess returned error exit status 1
      No apport report written because MaxReports is reached already
                                                                    Errors were encountered while processing:
       pychess
       python-pkg-resources
       gir1.2-dee-1.0
       python3-minimal
      needrestart is being skipped since dpkg has failed
      E: Sub-process /usr/bin/dpkg returned an error code (1)
    
    • sudo dpkg --configure -a and sudo apt -f install, result in the same errors.
    • The dpkg recovery instructions (as for i.e. How to reinstall dpkg) don't work either since there aren't i.e. the required files at /var/cache/apt/archives/.

    I tried to get the .deb packages straight from Ubuntu's website, extract them and install them separately.

    Given the fact that according to the forum posts that I've been going through, people have been breaking their Ubuntu and other Debian-based systems for at least the past ten years whenever something has gone haywire with Python - be it user error or a package breaking things, would it be a bit safer to somehow make a fundamental fix in the way the dpkg/apt architecture is handled in Linux and isolate whatever Python modules and dependencies they need to run from the rest of the operating system? Or to create some sort of a fail-safe system restore method in cases of these kinds of grievous situations which seem to be quite prevalent.

    • Thomas Ward
      Thomas Ward almost 4 years
      Also, bug reports such as these are not supposed to be here. This counts in that category of posts because you are reporting bugs in the packages on arm64. This being said, if Python is broken in your environment chances are you're going to have a lot of other problems when attempting to update packages. Did you change python versions on your computer for some reason? (You should NEVER update python manually)
    • user535733
      user535733 almost 4 years
      "I broke it, therefore it must be a flawed design" is not a logically consistent argument, and is unlikely to be seriously entertained by the apt development community. You have encountered the learning curve. We all encountered and overcame it, too. Welcome.
    • WhatOnEarthOrOutsideIt
      WhatOnEarthOrOutsideIt almost 4 years
      @user535733 There are plenty other OS's around there that don't break apart if you accidentally install a newer Python version from source and replace the one already on the system. What happened to the concept of anti-fragility, robustness or redundancy? Ever so often you do get the impression that Linux is like the long distance marathon runner that forgot to tie his or her shoelaces before the run. Saying that I should just take a broken OS over such common mishap as a part of learning curve only makes people to toss their Linux builds out the window, especially with "support" like this.
    • WhatOnEarthOrOutsideIt
      WhatOnEarthOrOutsideIt almost 4 years
      @user535733 Instead of getting answers, or instead of anyone addressing the fact that yep, indeed, this is a common issue that should have some sort of mitigation or revert measure in order for perfectly-working builds to not come apart just like that (note that there are innumerable reasons for Python to break down, that's why having a method to revert to the default system installation would be more than sorely needed, IMHO) - the "answers" thus far have just been cop-outs in order to NOT to face the fundamental design flaws that may break a Linux install apart at any given moment. Not good.
    • user535733
      user535733 almost 4 years
      Ubuntu is a collection of dozens of independent upstream projects. If you have a real suggestion for making Python installs more robust and less version-fragile, that 1) Does not break that upstream packages that Ubuntu distributes, and that 2) Does not assume additional technical debt by Ubuntu volunteers or Canonical engineers, then the Ubuntu Foundations Team would be interested in seeing it. Advice: Keep it very, very short; they are already more familiar with the problem than you are -- they have been trying and discarding failed solutions for 15 years.
  • WhatOnEarthOrOutsideIt
    WhatOnEarthOrOutsideIt almost 4 years
    Like I said in my original post, which no matter how I word it, nobody ever seems to read, my backup image was corrupted for some reason. Given the amount of work and effort I've put into making the install just right, I'd rather just give up at this point than start from scratch, and there's that.
  • Organic Marble
    Organic Marble almost 4 years
    This - there's no way to bulletproof your feet.
  • WhatOnEarthOrOutsideIt
    WhatOnEarthOrOutsideIt almost 4 years
    Thanks for the reply, I will try that one out next. @OrganicMarble Again, that's a cop-out imho. Since the problem isn't just "users running random sudo commands" (lol, srsly), but rather, since these kind of "Python breaks down, the entire install is screwed since apt or dpkg doesn't work anymore"-scenarios have happened - according to all the forum posts that I found - for over 10 years, as I stated earlier, anyone who is a Linux dev should look up a method of "sandboxing" dpkg and apt to make them resilient to things breaking down over in Python. It used to be called software DEVELOPMENT.
  • WhatOnEarthOrOutsideIt
    WhatOnEarthOrOutsideIt almost 4 years
    @OrganicMarble The counter-analogy to "There's no way to bulletproof your feet" would be "I don't see a problem laying the foundation of this house on toothpicks." -- just an IMHO, but there's multiple endemic problems plaguing Linux and one crucial part of them is the packet management that in of itself can break things very easily. Many of the Python woes similar to mine had nothing to do with installing Python from source and/or overwriting the system installation. All it took was some components of Python itself to break down due this or that => end result: basically an unfixable quagmire.
  • WhatOnEarthOrOutsideIt
    WhatOnEarthOrOutsideIt almost 4 years
    THANK YOU SO MUCH @BrianTurek ! I managed to get the packages in right order out of that repository and after a few hit-and-misses on the installation order with dpkg, all's working now! I almost can't believe this. It actually WORKED! I owe you a drink for this one. A big one. This means more than you might realize. <3 Thank you! And as for all the naysayers out there ("just toss it overboard, it's done for"), let this be a living proof of what can be done to fix up a screwed up Python install.
  • Brian Turek
    Brian Turek almost 4 years
    I'm glad it worked for you! I was worried dpkg was going to be broken as well which would have slowed down the recovery process a bit. It would be awesome if you could accept my answer :)
  • WhatOnEarthOrOutsideIt
    WhatOnEarthOrOutsideIt almost 4 years
    @BrianTurek ... Except now I ran into some troubles with i.e. pkg_resources. Seems to be missing and causing a problem here and there. Been trying to go through the site you linked and install it from there, doesn't seem very co-operative. dpkg , apt and aptitude all work, but it's those few that are still elusive. I've been trying my best to follow the crumb-trails on what's dependent on what but it's a quagmire. Well, at least I'm not the only one who's broken their entire Linux due to a Python problem -- there should be a solution to reverting a broken Python install more easily.
  • WhatOnEarthOrOutsideIt
    WhatOnEarthOrOutsideIt almost 4 years
    @BrianTurek -- I'm wondering if all else fails, I'll install a new Ubuntu 20.04LTS on another MicroSD on the RPi4B and overwrite-copy / rsync the key system files (esp. Python related) from that one on top of the broken one? Could that work, so that I don't have to start from scratch with the entire installation. I've been working on the build and tweaking it for the RPi4B ever since the model came out (ran the 18.04LTS before that.), up until now that was my best-working desktop that had literally everything in a working order; cross-compiled a lot to make it work on the arm64, etc., etc.
  • Brian Turek
    Brian Turek almost 4 years
    That would also work and is essentially the same as restoring from a (non-corrupted) backup :) At the end of the day a Linux-based Python installation is just files so you just need to overwrite the "bad" ones with known good ones.