繁体   English   中英

Windows Ubuntu Bash shell 上的 Python3.7 导入错误:无法从 'urllib.request' (/usr/lib/python3.7/urllib/request.py) 导入名称 'HTTPSHandler'

[英]Python3.7 on Windows Ubuntu Bash shell ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (/usr/lib/python3.7/urllib/request.py)

我最近将 Python 从 3.5 版更新到了 3.7 版,并将其设为我的 bash shell 中的默认值。 我还更新了 pip 并确保它使用 Python3.7。

现在,每当我尝试使用 pip 安装任何模块时,都会出现此错误”

$pip3 install google 
Traceback (most recent call last):   File "/home/AnnaK/.local/bin/pip3", line 7, in <module>
    from pip._internal.cli.main import main   File "/usr/lib/python3/dist-packages/pip/__init__.py", line 16, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa   File "/usr/lib/python3/dist-packages/pip/vcs/subversion.py", line 9, in <module>
    from pip.index import Link   File "/usr/lib/python3/dist-packages/pip/index.py", line 30, in <module>
    from pip.wheel import Wheel, wheel_ext   File "/usr/lib/python3/dist-packages/pip/wheel.py", line 39, in <module>
    from pip._vendor.distlib.scripts import ScriptMaker   File "/usr/share/python-wheels/distlib-0.2.2-py2.py3-none-any.whl/distlib/scripts.py", line 14, in <module>   File "/usr/share/python-wheels/distlib-0.2.2-py2.py3-none-any.whl/distlib/compat.py", line 66, in <module> ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (/usr/lib/python3.7/urllib/request.py)

如果我尝试简单地运行 pip,我会得到同样的错误。 这在我使用 python3.5 时没有发生。 我在短暂使用 python2.7 时确实遇到了这个问题,但我使用https://askubuntu.com/questions/581999/pip-raises-importerror-cannot-import-name-httpshandler修复了它。 该解决方案似乎不适用于 python3.7。

我尝试重新安装 pip,重新安装 python3,更新我的 Windows Ubuntu 子系统,并重新安装 libssl-dev。 我难住了。 任何帮助表示赞赏!

您一定是无意中升级了系统 pip(可能是通过sudo pip install pip --upgrade

pip xx 调整其内部结构的位置。 您看到的pip3命令是由您的包维护者提供的,而不是由 pip 管理的文件。

您可以在pip 的问题跟踪器上阅读有关此内容的更多信息

你可能会想升级系统PIP和改为使用的virtualenv。

要恢复pip3二进制文件,您需要sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

如果您使用第一种方法python3 -m pip ...而不是pip3 ...它应该可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM