I've recently updated WLS2-Win11 to Ubuntu 24.04 on my Intel-CPU computer. After removing Python 3.8, I tried installing Python 3.12.
Command sudo apt-get update; sudo apt-get upgrade
leads to the following error:
... The following upgrades have been deferred due to phasing: libopeniscsiusr needrestart open-iscsiThe following packages have been kept back: bind9-dnsutils bind9-host bind9-libs binutils binutils-common binutils-x86-64-linux-gnu btrfs-progs build-essential chafa coreutils cpp cpp-11 cpp-9 cron cryptsetup-initramfs curl dbus dbus-user-session dbus-x11 dirmngr dmeventd e2fsprogs file fonts-dejavu-core fonts-urw-base35 fuse fwupd g++ g++-11 gcc gcc-11 gcc-11-base gcc-9 gcc-9-base ghostscript git git-man gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv gsfonts imagemagick-6.q16 initramfs-tools initramfs-tools-bin initramfs-tools-core iproute2 jp2a libalgorithm-diff-xs-perl libargon2-1 libasan5 libasan6 libbinutils libcairo2 libctf0 libdbus-1-3 libfido2-1 libfile-fcntllock-perl libfreetype6 libfwupd2 libgcc-11-dev libgcc-9-dev libgd3 libgl1-amber-dri libgl1-mesa-dri libglapi-mesa libglx-mesa0 libgudev-1.0-0 libheif1 libintl-perl libintl-xs-perl libjxr-tools liblocale-gettext-perl liblvm2cmd2.03 libmagic-mgc libmm-glib0 libncurses6 libncursesw6 libnsl2 libnss-nisplus libnss-systemd libpam-modules libpam-modules-bin libpam-systemd libplymouth5 libpolkit-agent-1-0 libpolkit-gobject-1-0 libproc-processtable-perl libpulse0 libqmi-glib5 libqmi-proxy libsemanage-common libserf-1-1 libsndfile1 libstdc++-11-dev libsvn1 libsystemd0 libterm-readkey-perl libtext-charwidth-perl libtext-iconv-perl libtinfo6 libtsan0 libudev1 libvolume-key1 libwebp7 libwebpdemux2 libwebpmux3 libxaw7 libxml2 lsof lvm2 mesa-vulkan-drivers modemmanager multipath-tools ncurses-base ncurses-bin ncurses-term netpbm ntfs-3g open-vm-tools parted passwd perl perl-base pkexec plymouth plymouth-theme-ubuntu-text policykit-1 polkitd procps pulseaudio-utils sg3-utils subversion systemd systemd-sysv systemd-timesyncd tcpdump telnet thin-provisioning-tools tmux udev udisks2 w3m w3m-img wget x11-utils zerofree0 upgraded, 0 newly installed, 0 to remove and 156 not upgraded.1 not fully installed or removed.After this operation, 0 B of additional disk space will be used.---------------------------------------------------------------------Setting up python3 (3.12.3-0ubuntu1) ...running python rtupdate hooks for python3.12...running python post-rtupdate hooks for python3.12.../var/lib/dpkg/info/python3.postinst: 47: py3compile: not founddpkg: error processing package python3 (--configure): installed python3 package post-installation script subprocess returned error exit status 127Errors were encountered while processing: python3needrestart is being skipped since dpkg has failed
At this time, no python was installed on my machine. I tried sudo apt-get install python3 --reinstall
, and it returned
Reading package lists... DoneBuilding dependency tree... DoneReading state information... Done0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 156 not upgraded.1 not fully installed or removed.After this operation, 0 B of additional disk space will be used.E: Internal Error, No file name for python3:amd64
Command whereis python3
returned python3: /usr/lib/python3 /etc/python3 /usr/share/python3
. Commands sudo dpkg --configure -a
, sudo apt autoremove
and sudo apt-get install -f
returned simmilar error as sudo apt-get upgrade
shown above.
Command sudo apt remvoe python3
returned:
Reading package lists... DoneBuilding dependency tree... DoneReading state information... DoneThe following package was automatically installed and is no longer required: libpython3-stdlibUse 'sudo apt autoremove' to remove it.The following packages will be REMOVED: python30 upgraded, 0 newly installed, 1 to remove and 156 not upgraded.1 not fully installed or removed.After this operation, 84.0 kB disk space will be freed.Do you want to continue? [Y/n] Ydpkg: warning: files list file for package 'python3.12-minimal' missing; assuming package has no files currently installeddpkg: warning: files list file for package 'python3.12' missing; assuming package has no files currently installeddpkg: warning: files list file for package 'python3-minimal' missing; assuming package has no files currently installed(Reading database ... 35623 files and directories currently installed.)Removing python3 (3.12.3-0ubuntu1) .../var/lib/dpkg/info/python3.prerm: 5: py3clean: not founddpkg: error processing package python3 (--remove): installed python3 package pre-removal script subprocess returned error exit status 127dpkg: too many errors, stopping/var/lib/dpkg/info/python3.postinst: 47: py3compile: not founddpkg: error while cleaning up: installed python3 package post-installation script subprocess returned error exit status 127Errors were encountered while processing: python3Processing was halted because there were too many errors.needrestart is being skipped since dpkg has failedE: Sub-process /usr/bin/dpkg returned an error code (1)
Q1: how can I fix it w/o reinstalling ubuntu?
Q2: If it's necessary to reintall ubuntu? How can I retain data given this WSL2 environment?
Update 1
Results of sudo apt list ...
python3-minimal/noble,now 3.12.3-0ubuntu1 amd64 [installed,automatic]python3.12-minimal/noble,now 3.12.3-1 amd64 [installed,automatic]
The result of file $(which apt)
/usr/bin/apt: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=8c9aa55bd74c35500c2014ff0674dd5eb481b82b, for GNU/Linux 3.2.0, stripped
And python3[.12]
returns command not found
Update 2
Command sudo apt install --reinstall python3-minimal python3.12-minimal
returns
dpkg: warning: files list file for package 'python3.12-minimal' missing; assuming package has no files currently installeddpkg: warning: files list file for package 'python3.12' missing; assuming package has no files currently installeddpkg: warning: files list file for package 'python3-minimal' missing; assuming package has no files currently installed(Reading database ... 35623 files and directories currently installed.)Preparing to unpack .../python3.12-minimal_3.12.3-1_amd64.deb ...Unpacking python3.12-minimal (3.12.3-1) over (3.12.3-1) ...Setting up python3.12-minimal (3.12.3-1) ...# Empty sitecustomize.py to avoid a dangling symlinkCould not find platform independent libraries <prefix>Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = '/usr/bin/python3.12' isolated = 0 environment = 0 user site = 1 safe_path = 0 import site = 0 is in build tree = 0 stdlib dir = '/usr/lib/python3.12' sys._base_executable = '/usr/bin/python3.12' sys.base_prefix = '/usr' sys.base_exec_prefix = '/usr' sys.platlibdir = 'lib' sys.executable = '/usr/bin/python3.12' sys.prefix = '/usr' sys.exec_prefix = '/usr' sys.path = ['/usr/lib/python312.zip','/usr/lib/python3.12','/usr/lib/python3.12/lib-dynload', ]Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encodingPython runtime state: core initializedModuleNotFoundError: No module named 'encodings'Current thread 0x00007fe6d634e080 (most recent call first):<no Python frame>dpkg: error processing package python3.12-minimal (--configure): installed python3.12-minimal package post-installation script subprocess returned error exit status 1Errors were encountered while processing: python3.12-minimalneedrestart is being skipped since dpkg has failedE: Sub-process /usr/bin/dpkg returned an error code (1)
'Solution'
I tried everything I could find to fix it, but none of them work. Finally I reinstalled the entire wls-ubuntu.