1

In attempt to remove an older version of python, I removed something important, and now nothing works.

> python3
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/home/karm/bin/python3'
  sys.base_prefix = '/usr'
  sys.base_exec_prefix = '/usr'
  sys.executable = '/home/karm/bin/python3'
  sys.prefix = '/usr'
  sys.exec_prefix = '/usr'
  sys.path = [
    '/usr/lib/python38.zip',
    '/usr/lib/python3.8',
    '/usr/lib/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007f44dad8e740 (most recent call first): <no Python frame>

The output of whereis python is

python: /usr/bin/python3.9 /usr/bin/python2.7 /usr/bin/python /usr/bin/python3.8-config /usr/bin/python3.8 /etc/python3.9 /etc/python2.7 /etc/python /etc/python3.8 /usr/include/python2.7 /usr/include/python3.8 /usr/share/python /home/karm/bin/python

When I run export PYTHONHOME = /usr/ and export PYTHONHOME = /usr/bin/python3.9, the fields are fixed, but it doesn't work.

When I run sudo apt install -f, the output is

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
4 not fully installed or removed.
Need to get 47.6 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 python3 amd64 3.8.2-0ubuntu2 [47.6 kB]
Fetched 47.6 kB in 1s (77.5 kB/s) 
dpkg: error processing package python3 (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Errors were encountered while processing:
 python3
E: Sub-process /usr/bin/dpkg returned an error code (1)

It doesn't let me do anything. Is there a way to fix these issues without reinstalling the OS from boot drive?

KARM
  • 11

1 Answers1

0

Simply repair-reinstall your Python bases afresh:

sudo apt update
sudo apt-get install --reinstall python2.7 python3.6 python3.7 python3.8
sudo apt-get install --reinstall libpython2.7-minimal libpython3.6-minimal libpython3.7-minimal libpython3.8-minimal
sudo apt-get install --reinstall $(dpkg -S '/usr/lib/python3*' | cut -d ':' -f1 | cut -d ',' -f1 | sort | uniq | tr '\n' ' ')
muru
  • 197,895
  • 55
  • 485
  • 740