升级时出现致命 Python 错误/ImportError

升级时出现致命 Python 错误/ImportError

当尝试apt upgradeapt update-manager我收到以下错误:

Setting up update-notifier-common (3.168.1) ...
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 0x00007fa215e86700 (most recent call first):
Aborted (core dumped)
dpkg: error processing package update-notifier-common (--configure):
 subprocess installed post-installation script returned error exit status 134
dpkg: dependency problems prevent configuration of flashplugin-installer:
 flashplugin-installer depends on update-notifier-common (>= 0.119ubuntu2); however:
  Package update-notifier-common is not configured yet.

dpkg: error processing package flashplugin-installer (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                      Errors were encountered while processing:
 update-notifier-common
 flashplugin-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)

我已阅读了许多重复的问题,但没有一个解决方案对我有用。

使用 Ubuntu 14.04,默认使用 Python 2.7.12,我从源代码手动安装了 Python 3.5。我从未使用虚拟环境来处理多个版本。由于我对 Ubuntu 还很陌生,我不假思索地从中删除了许多 Python3.5 的文件和目录,尽管/usr/lib中仍然有 Python3 和 Python3.5 文件/usr/bin。尽管出现了致命错误,但 Python 2.7.12 仍然可以在 shell 中正常运行,并且python -V仍然显示 2.7.12 是默认版本。

$PYTHONHOME在取消设置和之后,会出现上述错误$PYTHONPATH。如果echo $PYTHONHOME不返回任何内容,然后PYTHONHOME在命令行中输入,则会收到以下错误(输入也是如此PYTHONPATH):

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 0x00007f57373f3700 (most recent call first):
Aborted (core dumped)

当我输入which python命令行返回时/usr/bin/python,该文件的链接目标确实是 Python2.7。如果我设置export PYTHONHOME=/usr并再次输入PYTHONHOME命令行,我会收到以下错误:

Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

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

当我将命令行目录移动到我的 python 目录并输入时,python -m encodings我收到以下内容:

/usr/bin/python: No module named encodings.__main__; 'encodings' is a package and cannot be directly executed

...所以我甚至不确定PYTHONPATH如果它显然不是一个模块,我该如何将其识别为模块。无论我如何设置PYTHONHOMEPYTHONPATH,到目前为止,我在运行时仍然会收到相同的错误apt upgrade

我尝试过的一些其他修复方法:

  • 所有这些命令运行都没有问题,但并没有修复错误

    apt update
    apt clean
    apt autoclean
    
  • apt autoremove并且apt-get -f install都产生相同的错误apt upgrade

  • 取消设置PYTHONPATHPYTHONHOME不能修复错误,也不能设置PYTHONHOME到指示的目录which python
  • 我尝试使用 Synaptic 包管理器来修复损坏的包,但这并不能修复错误。
  • 我检查以确保/usr/lib/command-not-found明确调用/usr/bin/python3,并且该文件确实存在(我没有删除它)。
  • 我的/lost+found目录目前是空的,所以没有可以从那里恢复的模块。
  • 使用apt-get install --reinstall python(和 相同的命令python3.5)会产生与 相同的错误apt upgrade

我找不到其他资源或答案来处理此错误。我是否应该尝试使用虚拟环境来隔离我的 python 版本的剩余文件?我是否应该尝试修复现在已损坏的 python3.5 手动安装,以及由于--reinstall python会产生致命错误,我该怎么做?

相关内容