i did a stupid mistake by deleting the python3.9 folder from /usr/bin as well as other folders (it's a long story why i did that).

when i tried to reinstall it by running sudo apt install python3.9 i got this kind of error showed in the screenshot.

Erro when reinstalling python3.9

i have no idea what's this "blueman", so i need some help resolving it because i want my python back and i don't know how to do so.

the entire output:

[sudo] password for yahia: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3.9 is already the newest version (3.9.1-4).
The following packages were automatically installed and are no longer required:
  libaom0:i386 libcodec2-0.9 libcodec2-0.9:i386 libdav1d4:i386
  libdbusmenu-qt5-2 libjs-excanvas libjs-jquery-flot
  libpcre3:i386 libvpx6:i386 libwavpack1:i386 libx264-160:i386
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 2343 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up blueman (2.1.4-1+b1) ...
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 = '/usr/bin/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.platlibdir = 'lib'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/usr'
  sys.exec_prefix = '/usr'
  sys.path = [
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 0x00007fd8882db740 (most recent call first):
<no Python frame>
dpkg: error processing package blueman (--configure):
 installed blueman package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)
  • Your system depends on Python. It's probably the quickest to restore from a backup.
    – Panki
    Nov 3, 2022 at 17:42
  • @Panki this is a Debian-based system, so no, it doesn’t depend on Python. Nov 3, 2022 at 17:48
  • Hm, the blueman package probably was just a package pending configuration (maybe that was automatically triggered by the "re"installation of python3.9, mabye from an earlier, interrupted run of apt?); one of the scripts that the package runs depends on working python. Possibly you could force the installation of python3.9 from package without checking external dependencies. But honestly: "It's a long story why I did that": Long story short, you shot your system, and if you can't list all the things you shouldn't have deleted, then chances are that spending time trying to fix it would best Nov 3, 2022 at 18:51
  • be spent on a fresh installation, after making sure you've backed up all data of value. Nov 3, 2022 at 18:51
  • @MarcusMüller the thing is that i started working with PyQt5 but i had some issues with something called API 12.9 or something i spent days looking for solutions, tried everything that could help without any positive result, so i thought about removing the entire python and reinstalling it again, don't remember exactly what error was throwed when i did "sudo apt remove python3", so i removed the entire thing from the lib and when i came to run "sudo apt install python3.9" this happens. that's all of it ... i was so stupid Nov 3, 2022 at 19:02

1 Answer 1


The system still considers python3.9 to be installed:

python3.9 is already the newest version (3.9.1-4).

This makes sense if you removed the files without removing the package. You therefore need to explicitly reinstall it:

sudo apt reinstall python3.9

Depending on what other files you deleted, you may need to reinstall other packages too. Here’s how to reinstall all Python packages you had installed:

sudo apt reinstall $(dpkg-query -W \*python\* | awk '$2 { print $1 }')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .