![如何在 ubuntu 上修复 python3](https://linux22.com/image/936969/%E5%A6%82%E4%BD%95%E5%9C%A8%20ubuntu%20%E4%B8%8A%E4%BF%AE%E5%A4%8D%20python3.png)
在尝试删除旧版本的 Python 时,我删除了一些重要的东西,现在什么都不起作用了。
> python3
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 = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/home/karm/bin/python3'
sys.base_prefix = '/usr'
sys.base_exec_prefix = '/usr'
sys.executable = '/home/karm/bin/python3'
sys.prefix = '/usr'
sys.exec_prefix = '/usr'
sys.path = [
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/lib-dynload',
]
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 0x00007f44dad8e740 (most recent call first):
<no Python frame>
的输出whereis python
是
python: /usr/bin/python3.9 /usr/bin/python2.7 /usr/bin/python /usr/bin/python3.8-config /usr/bin/python3.8 /etc/python3.9 /etc/python2.7 /etc/python /etc/python3.8 /usr/include/python2.7 /usr/include/python3.8 /usr/share/python /home/karm/bin/python
当我运行export PYTHONHOME = /usr/
和时export PYTHONHOME = /usr/bin/python3.9
,字段是固定的,但它不起作用。
当我运行时sudo apt install -f
,输出是
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
4 not fully installed or removed.
Need to get 47.6 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 python3 amd64 3.8.2-0ubuntu2 [47.6 kB]
Fetched 47.6 kB in 1s (77.5 kB/s)
dpkg: error processing package python3 (--configure):
package is in a very bad inconsistent state; you should
reinstall it before attempting configuration
Errors were encountered while processing:
python3
E: Sub-process /usr/bin/dpkg returned an error code (1)
它不让我做任何事情。有没有办法解决这些问题,而无需从启动驱动器重新安装操作系统?
答案1
只需重新修复并重新安装你的 Python 基础:
sudo apt update
sudo apt-get install --reinstall python2.7 python3.6 python3.7 python3.8
sudo apt-get install --reinstall libpython2.7-minimal libpython3.6-minimal libpython3.7-minimal libpython3.8-minimal
sudo apt-get install --reinstall $(dpkg -S '/usr/lib/python3*' | cut -d ':' -f1 | cut -d ',' -f1 | sort | uniq | tr '\n' ' ')