需要为 Python 3.5.1 安装 urllib2 [英] Need to install urllib2 for Python 3.5.1

查看:25
本文介绍了需要为 Python 3.5.1 安装 urllib2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Mac 运行 Python 3.5.1.我想使用 urllib2 模块.我尝试安装它,但我被告知它已被拆分为 urllib.requesturllib.error for Python 3.

I'm running Python 3.5.1 for Mac. I want to use urllib2 module. I tried installing it but I was told that it's been split into urllib.request and urllib.error for Python 3.

我的命令(现在从框架 bin 目录运行,因为它不在我的路径中):

My command (running from the framework bin directory for now because it's not in my path):

sudo ./pip3 install urllib.request

返回:

Could not find a version that satisfies the requirement urllib.request (from versions: )
No matching distribution found for urllib.request

我之前尝试一下安装 urllib2 时遇到了同样的错误.

I got the same error before when I tried to install urllib2 in one fell swoop.

推荐答案

警告:安全研究发现 PyPI 上的几个中毒包,包括一个名为 urllib 的包,它在安装时会回拨".如果您在 2017 年 6 月之后的某个时间使用了 pip install urllib,请尽快删除该软件包.

WARNING: Security researches have found several poisoned packages on PyPI, including a package named urllib, which will 'phone home' when installed. If you used pip install urllib some time after June 2017, remove that package as soon as possible.

你不能,也不需要.

urllib2 是 Python 2 中包含的库的名称.您可以使用 urllib.request 包含在 Python 3 中.urllib.request 库的工作方式与 urllib2 在 Python 2 中的工作方式相同.因为它已经包含,所以您不需要安装它.

urllib2 is the name of the library included in Python 2. You can use the urllib.request library included with Python 3, instead. The urllib.request library works the same way urllib2 works in Python 2. Because it is already included you don't need to install it.

如果您正在学习一个告诉您使用 urllib2 的教程,那么您会发现会遇到更多问题.您的教程是为 Python 2 而不是 Python 3 编写的.查找其他教程,或安装 Python 2.7 并在该版本上继续您的教程.你会发现 urllib2 带有那个版本.

If you are following a tutorial that tells you to use urllib2 then you'll find you'll run into more issues. Your tutorial was written for Python 2, not Python 3. Find a different tutorial, or install Python 2.7 and continue your tutorial on that version. You'll find urllib2 comes with that version.

或者,安装 requests以获得更高级别并且更易于使用 API.它适用于 Python 2 和 3.

Alternatively, install the requests library for a higher-level and easier to use API. It'll work on both Python 2 and 3.

这篇关于需要为 Python 3.5.1 安装 urllib2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆