In an attempt to clear the file system on WSL2, I uninstalled python3 via
sudo rm -rf /usr/bin/python3
sudo rm -rf /usr/lib/python3
sudo rm -rf /usr/local/lib/python3
In turn, I am struggling to reinstall and use python3.* through WSL. When trying to reinstall python3 through sudo apt-get install --reinstall python3, I was presented with something similar to the following error.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
htop libnl-3-200 libnl-genl-3-200 libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python-pkg-resources python-setuptools python2 python2-minimal python2.7 python2.7-minimal
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 22 not upgraded.
40 not fully installed or removed.
Need to get 0 B/22.8 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 99157 files and directories currently installed.)
Preparing to unpack .../python3_3.10.6-1~22.04.1_amd64.deb ...
/var/lib/dpkg/info/python3.prerm: 5: py3clean: not found
dpkg: warning: old python3 package pre-removal script subprocess returned error exit status 127
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 5: py3clean: not found
dpkg: error processing archive /var/cache/apt/archives/python3_3.10.6-1~22.04.1_amd64.deb (--unpack):
new python3 package pre-removal script subprocess returned error exit status 127
/var/lib/dpkg/info/python3.postinst: 47: py3compile: not found
dpkg: error while cleaning up:
installed python3 package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
/var/cache/apt/archives/python3_3.10.6-1~22.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
This lead me down several rabbit holes, where I was unequipped to understand. I went through the following command in a similar order, before realizing I might have created a much larger problem...
sudo apt purge python3
------
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
apport-symptoms bc blt debhelper debugedit devhelp-common dh-autoreconf dh-strip-nondeterminism distro-info distro-info-data dwz eatmydata fdisk fonts-lyx gdisk gir1.2-atk-1.0 gir1.2-atspi-2.0 gir1.2-freedesktop gir1.2-gdkpixbuf-2.0
gir1.2-glib-2.0 gir1.2-gtk-2.0 gir1.2-gtk-3.0 gir1.2-harfbuzz-0.0 gir1.2-packagekitglib-1.0 gir1.2-pango-1.0 htop icu-devtools intltool-debian libappstream4 libarchive-cpio-perl libarchive-zip-perl libatk1.0-doc libblkid-dev
libboost-dev libboost1.74-dev libbrotli-dev libcairo-script-interpreter2 libdatrie-dev libdbus-1-dev libdebhelper-perl libdeflate-dev libdevhelp-3-6 libeatmydata1 libegl-dev libegl1-mesa-dev libepoxy-dev libevent-core-2.1-7 libfdisk1
libffi-dev libfile-stripnondeterminism-perl libfontconfig-dev libfontconfig1-dev libfreetype-dev libfreetype6-dev libfribidi-dev libgail-common libgail18 libgl-dev libgles-dev libgles1 libglib2.0-bin libglib2.0-doc libglvnd-core-dev
libglvnd-dev libglx-dev libgraphite2-dev libgtk-3-doc libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libharfbuzz-gobject0 libice-dev libicu-dev libimagequant0 libjbig-dev libjpeg-dev libjpeg-turbo8-dev libjpeg8-dev libjs-jquery
libjs-jquery-ui libjs-sphinxdoc libjs-underscore liblbfgsb0 liblzma-dev libmail-sendmail-perl libmount-dev libncurses-dev libnetplan0 libnl-3-200 libnl-genl-3-200 libopengl-dev libopengl0 libopenjp2-7 libpackagekit-glib2-18
libpango1.0-doc libpangoxft-1.0-0 libpcre16-3 libpcre2-16-0 libpcre2-32-0 libpcre2-dev libpcre2-posix3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libpfm4 libpixman-1-dev libpng-dev libpng-tools libpython2-stdlib libpython2.7-minimal
libpython2.7-stdlib libpython3-stdlib libqhull-r8.0 libraqm0 libselinux1-dev libsepol-dev libsm-dev libstemmer0d libsub-override-perl libsys-hostname-long-perl libtcl8.6 libthai-dev libtiff-dev libtiffxx5 libtinfo-dev libtk8.6
libutempter0 libwayland-bin libwayland-dev libxcb-render0-dev libxcb-shm0-dev libxcomposite-dev libxcursor-dev libxdamage-dev libxfixes-dev libxft-dev libxi-dev libxinerama-dev libxkbcommon-dev libxml2-dev libxml2-utils libxmlb2
libxrandr-dev libxrender-dev libxsimd-dev libxtst-dev libyaml-0-2 libz3-4 libz3-dev llvm-14 llvm-14-runtime packagekit packagekit-tools pango1.0-tools po-debconf python-apt-common python-babel-localedata python-matplotlib-data
python-pkg-resources python-setuptools python2 python2-minimal python2.7 python2.7-minimal python3-minimal python3-pip-whl python3-setuptools-whl python3.10 python3.10-dev python3.10-minimal run-one screen tk8.6-blt2.5 tmux
unicode-data uuid-dev wayland-protocols
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
apport* byobu* cloud-guest-utils* cloud-init* command-not-found* devhelp* landscape-client* landscape-common* libatk-bridge2.0-dev* libatk1.0-dev* libatspi2.0-dev* libcairo2-dev* libgdk-pixbuf-2.0-dev* libglib2.0-dev*
libglib2.0-dev-bin* libgtk-3-dev* libgtk2.0-dev* libharfbuzz-dev* libpango1.0-dev* llvm-14-dev* llvm-14-tools* lsb-release* netplan.io* networkd-dispatcher* pastebinit* plymouth-theme-ubuntu-text* python3* python3-appdirs*
python3-apport* python3-apt* python3-attr* python3-automat* python3-babel* python3-backcall* python3-bcrypt* python3-beniget* python3-blinker* python3-brotli* python3-bs4* python3-certifi* python3-cffi-backend* python3-chardet*
python3-click* python3-colorama* python3-commandnotfound* python3-configobj* python3-constantly* python3-cryptography* python3-cycler* python3-dateutil* python3-dbus* python3-debconf* python3-decorator* python3-dev* python3-distro*
python3-distro-info* python3-distupgrade* python3-distutils* python3-fonttools* python3-fs* python3-gast* python3-gdbm* python3-gi* python3-hamcrest* python3-html5lib* python3-httplib2* python3-hyperlink* python3-idna*
python3-importlib-metadata* python3-incremental* python3-ipython* python3-jedi* python3-jeepney* python3-jinja2* python3-json-pointer* python3-jsonpatch* python3-jsonschema* python3-jwt* python3-keyring* python3-kiwisolver*
python3-launchpadlib* python3-lazr.restfulclient* python3-lazr.uri* python3-lib2to3* python3-lxml* python3-lz4* python3-markupsafe* python3-matplotlib* python3-matplotlib-inline* python3-more-itertools* python3-mpmath*
python3-netifaces* python3-newt* python3-numpy* python3-oauthlib* python3-olefile* python3-openssl* python3-packaging* python3-parso* python3-pexpect* python3-pickleshare* python3-pil* python3-pil.imagetk* python3-pip*
python3-pkg-resources* python3-ply* python3-problem-report* python3-prompt-toolkit* python3-ptyprocess* python3-pyasn1* python3-pyasn1-modules* python3-pycurl* python3-pygments* python3-pyparsing* python3-pyrsistent* python3-pythran*
python3-requests* python3-scipy* python3-secretstorage* python3-serial* python3-service-identity* python3-setuptools* python3-six* python3-software-properties* python3-soupsieve* python3-sympy* python3-systemd* python3-tk*
python3-traitlets* python3-twisted* python3-tz* python3-ufolib2* python3-unicodedata2* python3-update-manager* python3-urllib3* python3-venv* python3-wadllib* python3-wcwidth* python3-webencodings* python3-wheel* python3-yaml*
python3-zipp* python3-zope.interface* python3.10-venv* python3.11-venv* software-properties-common* ubuntu-advantage-tools* ubuntu-minimal* ubuntu-pro-client* ubuntu-pro-client-l10n* ubuntu-release-upgrader-core* ubuntu-wsl* ufw*
unattended-upgrades* update-manager-core*
0 upgraded, 0 newly installed, 155 to remove and 21 not upgraded.
40 not fully installed or removed.
After this operation, 548 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 99157 files and directories currently installed.)
Removing cloud-init (24.4.1-0ubuntu0~22.04.1) ...
/var/lib/dpkg/info/cloud-init.prerm: 21: py3clean: not found
dpkg: error processing package cloud-init (--remove):
installed cloud-init package pre-removal script subprocess returned error exit status 127
dpkg: too many errors, stopping
/var/lib/dpkg/info/cloud-init.postinst: 423: py3compile: not found
dpkg: error while cleaning up:
installed cloud-init package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
cloud-init
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)
I've been trying to understand this for much longer than I'd like to admit. There are also quite a few existing threads on this subject; however, the conversations have not been enough to help me through this.
EDIT: I was asked for my Ubuntu version. I'd love to hear how else I may find this, but using lsb_release -a gives the following error.
-bash: /usr/bin/lsb_release: /usr/bin/python3: bad interpreter: No such file or directory
