Pip3 根本不起作用

Pip3 根本不起作用

几天前,我遇到了一个问题,pip3 停止工作了。我本来打算升级我的 WSL2,所以我刚刚迁移到了 Ubuntu 20。但这里也出现了同样的问题!我无法安装任何事物使用 pip3。 Pip 不工作!

使用 -vvv 会产生完全相同的结果 - 什么都没有。我已经尝试重新安装:

sudo apt purge *python3-pip* && sudo apt install python3-pip

是的,我等了大约 20 分钟,什么都没发生。运行 时帮助菜单有效pip3pip3 freeze命令有效,但安装和卸载无效。可能无关紧要,但这是我使用 Ctrl+C 将其杀死时收到的消息:

  File "/usr/bin/pip3", line 11, in <module>
    load_entry_point('pip==20.0.2', 'console_scripts', 'pip3')()
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
    command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
    module = importlib.import_module(module_path)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/uninstall.py", line 9, in <module>
    from pip._internal.cli.req_command import SessionCommandMixin
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 19, in <module>
    from pip._internal.network.session import PipSession
  File "/usr/lib/python3/dist-packages/pip/_internal/network/session.py", line 26, in <module>
    from pip._internal.network.auth import MultiDomainBasicAuth
  File "/usr/lib/python3/dist-packages/pip/_internal/network/auth.py", line 36, in <module>
    import keyring  # noqa
  File "/usr/lib/python3/dist-packages/keyring/__init__.py", line 3, in <module>
    from .core import (
  File "/usr/lib/python3/dist-packages/keyring/core.py", line 189, in <module>
    init_backend()
  File "/usr/lib/python3/dist-packages/keyring/core.py", line 93, in init_backend
    keyrings = filter(limit, backend.get_all_keyring())
  File "/usr/lib/python3/dist-packages/keyring/util/__init__.py", line 21, in wrapper
    func.always_returns = func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/keyring/backend.py", line 210, in get_all_keyring
    return list(rings)
  File "/usr/lib/python3/dist-packages/keyring/util/__init__.py", line 31, in suppress_exceptions
    for callable in callables:
  File "/usr/lib/python3/dist-packages/keyring/util/properties.py", line 26, in __get__
    return self.fget.__get__(None, owner)()
  File "/usr/lib/python3/dist-packages/keyring/backend.py", line 67, in viable
    cls.priority
  File "/usr/lib/python3/dist-packages/keyring/util/properties.py", line 26, in __get__
    return self.fget.__get__(None, owner)()
  File "/usr/lib/python3/dist-packages/keyring/backends/kwallet.py", line 140, in priority
    return super(DBusKeyringKWallet4, cls).priority - 1
  File "/usr/lib/python3/dist-packages/keyring/util/properties.py", line 26, in __get__
    return self.fget.__get__(None, owner)()
  File "/usr/lib/python3/dist-packages/keyring/backends/kwallet.py", line 37, in priority
    bus = dbus.SessionBus(mainloop=DBusGMainLoop())
  File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 212, in __new__
    return Bus.__new__(cls, Bus.TYPE_SESSION, private=private,
  File "/usr/lib/python3/dist-packages/dbus/_dbus.py", line 102, in __new__
    bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 124, in __new__
    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
  File "/usr/lib/python3/dist-packages/dbus/exceptions.py", line 47, in __init__
    def __init__(self, *args, **kwargs):
KeyboardInterrupt

我被难住了!这是一个非常烦人的错误。如果这很重要,我正在使用来自 Microsoft Store 的 WSL2 和 Ubuntu 20.04 LTS。谢谢!

答案1

感谢 Anaksunaman 在评论中指出的问题,我终于搞清楚了。我跟着这个帖子在 GitHub 上,它成功了!

事实证明,问题出在我使用的 X-Server 中导出 DISPLAY 变量。一旦我从 .bashrc 中注释掉该行,pip 就可以再次工作了。

如果有人能解释我将不胜感激为什么这句话在评论中被打破了:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

相关内容