Why is python3 not working?

python version is used python3.8 It gives this error when I run python3

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 = '/usr/bin/python3'
  sys.base_prefix = '/usr'
  sys.base_exec_prefix = '/usr'
  sys.executable = '/usr/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'
1 Like

Hi Milad,

for anybody here to be able to help you diagnose this problem, you’re going to have to provide a bit more information:

What operating system are you using? What version (and distribution)? How did you install Python 3.8?

You’ve shown us that the python3 command doesn’t work. Can you start Python or some Python program in any other way that you know of?

1 Like

operating system = Ubuntu 20.04
already python 3.8 was installed suddenly Python did not work and even some programs do not work like terminal or software update etc.

any Python program doesn’t work

Isn’t this a problem? PAYTHONHOME , PAYTHONPATH is not set.

1 Like

When I execute this command sudo apt update , it gives the same error again.

1 Like

What do you mean, “suddently”? Did you do anything between Python working and Python not working?

Anyway it looks like your Python installation is somehow missing some core components. This is not something that happens just like that, and depending on what caused it it’s possible a lot more of your system is broken.

You may be able to fix this by reinstalling all core Python 3.8 packages. (At the very least libpython3.8-minimal, which should contain /usr/lib/python3.8/encodings/*.

2 Likes

ls /usr/lib/python3.8/encodings

output:
'/usr/lib/python3.8/encodings': No such file or directory

1 Like

I think most Python3.8 files are deleted right?

1 Like

reinstalling all core Python 3.8 packages then SOLVED.
thank you very much

1 Like