我已经执行了这个命令
sudo rm /usr/bin/python3
sudo ln -s python3.5 /usr/bin/python3
此后,当我开始执行命令时,python3
出现此错误
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 587, in <module>
main()
File "/usr/lib/python3.5/site.py", line 573, in main
known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 1, in <module>
import importlib
File "/usr/lib/python3.5/importlib/__init__.py", line 57, in <module>
import types
File "/usr/lib/python3/dist-packages/gi/types.py", line 28, in <module>
from ._constants import TYPE_INVALID
ImportError: attempted relative import with no known parent package
有人能帮我解决这个问题吗?请注意,当我使用 Ubuntu 16.04 时,python 3.5 已经存在,然后当我将 Ubuntu 更新到 18.04 时,它要求我保留它。我保持原样。
答案1
# delete wrong symlink
sudo rm /usr/bin/python3
# install deleted python version
sudo apt install python3.6
# create symlink again
sudo ln -s python3.6 /usr/bin/python3
这很有可能会成功。
请不要在将来删除重要的二进制文件。