【问题标题】:urllib.request module fails to install in my systemurllib.request 模块无法在我的系统中安装
【发布时间】:2015-06-05 14:57:04
【问题描述】:

尝试使用以下命令安装 urllib.request 模块

sudo pip install urllib.request

但它返回了

Downloading/unpacking urllib.request
  Could not find any downloads that satisfy the requirement urllib.request
Cleaning up...
No distributions at all found for urllib.request
Storing debug log for failure in /home/mounarajan/.pip/pip.log

如何安装这个模块?

【问题讨论】:

  • 也许我遗漏了一些东西,但你为什么不直接安装urllib——即sudo pip install urllib。这不包括request吗?
  • 它也会抛出同样的错误
  • 我只是在墙上扔飞镖,但是sudo pip install urllib3 呢?这会让你得到你想要的吗?
  • 或者您可能需要安装与 python 3 兼容的pip 版本?

标签: python ubuntu pip urllib sudo


【解决方案1】:

urllib.request 仅在 python3 分支中可用。有关更多信息,请参阅以下帖子。 urllib.request in Python 2.7

【讨论】:

  • 是的,我使用 python 3
  • “python3 文件名.py”是什么意思?什么是“文件名.py”?
  • python3 是版本名,文件名是你在目录中保存程序的文件名,所以 python3 filename.py
【解决方案2】:

在 python3 中你必须使用 urllib3 模块。

$ pip3 install urllib3

或者,如果您使用的是虚拟环境:

$ pip install urllib3

【讨论】:

    【解决方案3】:

    在 python 2 中,你只需使用 urllib 例如

    import urllib
    htmlfile=urllib.urlopen("your url")
    htmltext=htmlfile.read()
    

    在python 3中,你需要使用urllib.request

    import urllib.request
    htmlfile=urllib.request.urlopen("your url")
    htmltext=htmlfile.read()
    

    【讨论】:

      【解决方案4】:

      对于cmd中的Python3,

      pip install urllib3
      

      或者,如果您使用的是 anaconda:

      conda install urllib3
      

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-21
        • 2022-01-19
        • 1970-01-01
        • 2017-05-30
        • 1970-01-01
        • 2017-05-02
        相关资源
        最近更新 更多