Problems with commands (python...)

Hello, I am having problems with command python. When I use command python it will do this:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

I can’t use python or its associated commands (pip, python). Where is problem and how to solve it?
When I want to install python (with apt install python) it will do this:

/var/lib/dpkg/info/python2.7.postinst: 9: /var/lib/dpkg/info/python2.7.postinst: /usr/bin/python2.7: not found
dpkg: error processing package python2.7 (--configure):
 installed python2.7 package post-installation script subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of python2:
 python2 depends on python2.7 (>= 2.7.16-1~); however:
  Package python2.7 is not configured yet.

dpkg: error processing package python2 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python:
 python depends on python2.7 (>= 2.7.16-1~); however:
  Package python2.7 is not configured yet.
 python depends on python2 (= 2.7.16-1); however:
  Package python2 is not configured yet.

dpkg: error processing package python (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python2.7
 python2
 python
E: Sub-process /usr/bin/dpkg returned an error code (1)

It seems you have messed up your OS by deleting things you’re not supposed to.

It’s not really a Python problem; rather, you have a missing Python problem which you need to recover from.

What OS are you using?

If you’re using Ubuntu, take a look in the following AskUbuntu Q&A: Deleted the python binary, and can't recover using apt-get, what can I do? - Ask Ubuntu

1 Like