Python3 не работает в Ubuntu после случайного удаления usr / lib / files

#python #python-3.x

#python #python-3.x

Вопрос:

Я использую Ubuntu 16.04 LTS, недавно я случайно удалил некоторые файлы и папки ( /urs/lib/pyhon3.x ), после этого Python3 не работает.

python3 выдает следующее сообщение об ошибке.

 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: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007f7e77307700 (most recent call first):
Aborted (core dumped)
  

Я попытался переустановить python3 с помощью
sudo apt-get install python3

Тем не менее, проблема сохраняется, я попытался отключить PYTHONHOME и отключить PYTHONPATH. Но ничего не работает, как мы можем заставить это работать?

Обновление (1) pip не работает, поскольку python не работает. pip install encodings возвращает следующую ошибку,

 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: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007f76e2667700 (most recent call first):
Aborted (core dumped
  

Обновление (2) :
Я пробовал

sudo apt-get --purge autoremove python3 затем перезагрузите, sudo apt install python3 ,

выдает следующую ошибку,

 Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3 is already the newest version (3.5.1-3).
0 upgraded, 0 newly installed, 0 to remove and 54 not upgraded.
2 not fully installed or removed.
Need to get 0 B/8 710 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
[master ccedc09] saving uncommitted changes in /etc prior to apt run
 Author: rajgourav <rajgourav@euclide.ipcms1.ipcms.unistra.fr>
 8 files changed, 4 insertions( ), 4 deletions(-)
Setting up python3.5 (3.5.2-2ubuntu0~16.04.12) ...
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007efddc85f700 (most recent call first):
Aborted (core dumped)
dpkg: error processing package python3.5 (--configure):
 subprocess installed post-installation script returned error exit status 134
dpkg: dependency problems prevent configuration of python3:
 python3 depends on python3.5 (>= 3.5.1-2~); however:
  Package python3.5 is not configured yet.

dpkg: error processing package python3 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup erro
r from a previous failure.
                          Errors were encountered while processing:
 python3.5
 python3
  

Комментарии:

1. sudo apt install --reinstall python3 возможно, вместо этого?

2. Привет, он тоже не работает. Возвращает ту же ошибку.

Ответ №1:

Я удалил python3 из своего ubuntu (18.0.4.5), чтобы посмотреть, смогу ли я воспроизвести ту же проблему.

Кажется, что удаление python и файлов конфигурации с помощью

sudo apt-get --purge autoremove python3

sudo reboot

затем

sudo apt install python3

работает

Комментарии:

1. Привет, я тоже пробовал это. Он не работает, я добавил сообщение об ошибке в последнюю часть вопроса, так как я не могу опубликовать длинную ошибку в комментариях. Пожалуйста, посмотрите.

Ответ №2:

Вы пытались установить кодировки модуля с pip install encodings помощью?

В противном случае попробуйте перенастроить Python3 с помощью dpkg с помощью команды sudo dpkg-reconfigure python3

Комментарии:

1. Привет, pip тоже не работает. `pip install encodings` выдает следующую ошибку. « Не удалось найти библиотеки, не зависящие от платформы <prefix> Не удалось найти библиотеки, зависящие от платформы <exec_prefix> Рассмотрите возможность установки в $PYTHONHOME значения <prefix>[:<exec_prefix>] Фатальная ошибка Python: Py_Initialize: не удалось получить кодировку языка ImportError: нет модуля с именем ‘encodings’ «