如何在 ubuntu 20.04 中安全地重新安装或修复 python3.8 并将其所有文件恢复为默认值?

如何在 ubuntu 20.04 中安全地重新安装或修复 python3.8 并将其所有文件恢复为默认值?

我正在摆弄 python3 和 pip,一些软件包似乎损坏了一些 python 文件,当我尝试使用 pip 时,我收到了这个错误和其他一些错误:

Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.8/dist-packages/pip/commands/install.py", line 249, in run
    with self._build_session(options) as session:
  File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 66, in _build_session
    session = PipSession(
  File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 321, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 93, in user_agent
    zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.8/dist-packages/pip/__main__.py", line 19, in <module>
    sys.exit(pip.main())
  File "/usr/local/lib/python3.8/dist-packages/pip/__init__.py", line 217, in main
    return command.main(cmd_args)
  File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 242, in main
    with self._build_session(
  File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 66, in _build_session
    session = PipSession(
  File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 321, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 93, in user_agent
    zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'

我尝试了几个小时使用相关问题上建议的方法,但都没有帮助

根据一些线程,您不应该删除 python3.8,因为许多系统资源都在使用它,那么我该如何修复它的所有文件并重新安装它?我希望它基本上恢复为默认值并删除所有已安装的软件包,我该怎么做?

答案1

您不必删除python3。这只会让事情变得更糟。相反,请pip按照以下命令删除并重新安装。

sudo apt remove python3-pip
sudo python3.8 -m easy_install pip

相关内容