我的 /usr/bin 中的 python 2 和 3 解释器不知何故被删除了,现在我无法重新安装。我看到之前有人问过类似的问题(我意外删除了 /usr/bin/python。如何恢复它?),但尝试使用重新安装sudo apt-get install --reinstall python2.7
失败,并显示以下消息和大约 15 个包的列表:
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
当我运行时,sudo apt --fix-broken install
它失败并显示以下错误消息:
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
/usr/bin/python2.7: can't open file '/usr/lib/python2.7/py_compile.py': [Errno 2] No such file or directory
dpkg: error processing package python2.7-minimal (--configure):
installed python2.7-minimal package post-installation script subprocess returned error exit status 2
dpkg: dependency problems prevent configuration of python-minimal:
python-minimal depends on python2.7-minimal (>= 2.7.15~rc1-1~); however:
Package python2.7-minimal is not configured yet.
dpkg: error processing package python-minimal (--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:
python2.7-minimal
python-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)
尽管在运行上述命令之前设置PYTHONHOME
为/usr/local/lib
或,也会发生这种情况。/usr/lib
首先尝试重新安装 python2.7-minimal 也会产生同样的错误。
我可以毫无困难地访问终端,并尝试使用重新安装 python3 ,结果sudo apt-get install python3-all
返回了与之前相同的错误 - E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution)
,并且还列出了一些软件包。
答案1
使用以下方法删除 Python 自带的库:
sudo apt autoremove
然后更新,
sudo apt update
然后安装 python,
sudo apt-get install python2.7