M BUZZ CRAZE NEWS
// news

Fatal Python error: init_import_size: Failed to import the site module

By Jessica Wood

Problem

I am running Ubuntu 20.04 LTS. I have both Python 3.8 and Python 3.9 installed, although Python 3.8 is broken.
When I type the command python3.8 into my terminal I get the following:

root@ubuntu-3pl:~# python3.8
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last): File "/usr/lib/python3.9/site.py", line 79, in <module> import os File "/usr/lib/python3.9/os.py", line 29, in <module> from _collections_abc import _check_methods File "/usr/lib/python3.9/_collections_abc.py", line 12, in <module> GenericAlias = type(list[int])
TypeError: 'type' object is not subscriptable

That to me looks like python3.8 is digging around in /usr/lib/python3.9, which is python3.9's library.
Here is the output of a few commands:

root@ubuntu-3pl:~# which python3.8
/usr/local/bin/python3.8
root@ubuntu-3pl:~# which python3
/usr/bin/python3
root@ubuntu-3pl:~# /usr/bin/python3 --version
Python 3.9.5
root@ubuntu-3pl:~# python3
Python 3.9.5 (default, Nov 23 2021, 15:27:38)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Python 3.9 works just fine, but Python 3.8 obviously does not work. I want Python 3.8 to work because I want to install landscape-common and various other packages which rely on it. This is what happens when I try to install landscape-common:

root@ubuntu-3pl:~# apt install landscape-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed: bc distro-info-data iso-codes libpython3-stdlib lsb-release python-apt-common python3 python3-apt python3-attr python3-automat python3-cffi-backend python3-click python3-colorama python3-configobj python3-constantly python3-cryptography python3-gdbm python3-hamcrest python3-hyperlink python3-idna python3-incremental python3-netifaces python3-openssl python3-pkg-resources python3-pyasn1 python3-pyasn1-modules python3-service-identity python3-six python3-twisted python3-twisted-bin python3-zope.interface python3.8
Suggested packages: isoquery python3-doc python3-tk python3-venv python3-apt-dbg python-apt-doc python-attr-doc python-configobj-doc python-cryptography-doc python3-cryptography-vectors python3-gdbm-dbg python-openssl-doc python3-openssl-dbg python3-setuptools python3-pampy python3-qt4 python3-serial python3-wxgtk2.8 python3-twisted-bin-dbg python3.8-venv python3.8-doc
The following NEW packages will be installed: bc distro-info-data iso-codes landscape-common libpython3-stdlib lsb-release python-apt-common python3 python3-apt python3-attr python3-automat python3-cffi-backend python3-click python3-colorama python3-configobj python3-constantly python3-cryptography python3-gdbm python3-hamcrest python3-hyperlink python3-idna python3-incremental python3-netifaces python3-openssl python3-pkg-resources python3-pyasn1 python3-pyasn1-modules python3-service-identity python3-six python3-twisted python3-twisted-bin python3-zope.interface python3.8
0 upgraded, 33 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 6362 kB/6410 kB of archives.
After this operation, 41.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 focal-updates/main amd64 python3.8 amd64 3.8.10-0ubuntu1~20.04.2 [387 kB]
Get:2 focal/main amd64 libpython3-stdlib amd64 3.8.2-0ubuntu2 [7068 B]
Get:3 focal-updates/main amd64 distro-info-data all 0.43ubuntu1.9 [4744 B]
Get:4 focal/main amd64 lsb-release all 11.1.0ubuntu2 [10.6 kB]
Get:5 focal/main amd64 python3-cffi-backend amd64 1.14.0-1build1 [68.7 kB]
Get:6 focal/main amd64 python3-netifaces amd64 0.10.4-1ubuntu4 [16.1 kB]
Get:7 focal/main amd64 python3-pkg-resources all 45.2.0-1 [130 kB]
Get:8 focal/main amd64 python3-six all 1.14.0-2 [12.1 kB]
Get:9 focal/main amd64 iso-codes all 4.4-1 [2695 kB]
Get:10 focal-updates/main amd64 python-apt-common all 2.0.0ubuntu0.20.04.6 [17.1 kB]
Get:11 focal-updates/main amd64 python3-apt amd64 2.0.0ubuntu0.20.04.6 [154 kB]
Get:12 focal-updates/main amd64 python3-gdbm amd64 3.8.10-0ubuntu1~20.04 [15.2 kB]
Get:13 focal/main amd64 bc amd64 1.07.1-2build1 [86.3 kB]
Get:14 focal/main amd64 python3-attr all 19.3.0-2 [33.9 kB]
Get:15 focal/main amd64 python3-automat all 0.8.0-1ubuntu1 [27.5 kB]
Get:16 focal/main amd64 python3-constantly all 15.1.0-1build1 [8244 B]
Get:17 focal/main amd64 python3-idna all 2.8-1 [34.6 kB]
Get:18 focal/main amd64 python3-hyperlink all 19.0.0-1 [33.5 kB]
Get:19 focal/main amd64 python3-incremental all 16.10.1-3.2 [14.9 kB]
Get:20 focal/main amd64 python3-zope.interface amd64 4.7.1-1 [85.2 kB]
Get:21 focal-updates/main amd64 python3-twisted-bin amd64 18.9.0-11ubuntu0.20.04.1 [11.1 kB]
Get:22 focal-updates/main amd64 python3-cryptography amd64 2.8-3ubuntu0.1 [211 kB]
Get:23 focal/main amd64 python3-openssl all 19.0.0-1build1 [43.3 kB]
Get:24 focal/main amd64 python3-pyasn1 all 0.4.2-3build1 [46.7 kB]
Get:25 focal/main amd64 python3-pyasn1-modules all 0.2.1-0.2build1 [32.9 kB]
Get:26 focal/main amd64 python3-service-identity all 18.1.0-5build1 [10.7 kB]
Get:27 focal/main amd64 python3-hamcrest all 1.9.0-3 [24.9 kB]
Get:28 focal-updates/main amd64 python3-twisted all 18.9.0-11ubuntu0.20.04.1 [1931 kB]
Get:29 focal/main amd64 python3-configobj all 5.0.6-4 [34.1 kB]
Get:30 focal-updates/main amd64 landscape-common amd64 19.12-0ubuntu4.2 [86.4 kB]
Get:31 focal/main amd64 python3-colorama all 0.4.3-1build1 [23.9 kB]
Get:32 focal/main amd64 python3-click all 7.0-3 [64.8 kB]
Fetched 6362 kB in 0s (22.5 MB/s)
Extracting templates from packages: 100%
Preconfiguring packages ...
Selecting previously unselected package python3.8.
(Reading database ... 123547 files and directories currently installed.)
Preparing to unpack .../python3.8_3.8.10-0ubuntu1~20.04.2_amd64.deb ...
Unpacking python3.8 (3.8.10-0ubuntu1~20.04.2) ...
Selecting previously unselected package libpython3-stdlib:amd64.
Preparing to unpack .../libpython3-stdlib_3.8.2-0ubuntu2_amd64.deb ...
Unpacking libpython3-stdlib:amd64 (3.8.2-0ubuntu2) ...
Setting up python3-minimal (3.8.2-0ubuntu2) ...
/var/lib/dpkg/info/python3-minimal.postinst: 5: py3compile: not found
dpkg: error processing package python3-minimal (--configure): installed python3-minimal package post-installation script subprocess returned error exit status 127
Errors were encountered while processing: python3-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

I installed Python 3.8.0 from . Here is the result of compgen -c python:

root@ubuntu-3pl:~# compgen -c python
python3.8-config
python3.8
python2
python3.9
python2.7
python3.9-config
python3
python
python2
python3.9
python2.7
python3.9-config
python3
python

Question

How can I either:

  • Uninstall all traces of Python 3.8 and successfully reinstall it?
  • Fix it so that it runs?
  • Install landscape-common using Python 3.9?

Any help/advice is very welcome! I am happy to try anything aside from reinstalling the OS.

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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