无法在 Python 中导入 urllib
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40050630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot import urllib in Python
提问by Square9627
I would like to import urllib
to use the function 'request
'. However, I encountered an error when trying to download via Pycharm:
我想导入urllib
以使用函数“ request
”。但是,我在尝试通过 Pycharm 下载时遇到错误:
"Could not find a version that satisfies the requirement urllib (from versions: ) No matching distribution found for urllib"
“找不到满足 urllib 要求的版本(来自版本:)没有找到与 urllib 匹配的发行版”
I tried pip install urllib
but still had the same error. I am using Python 2.7.11. Really appreciate any help
我试过了,pip install urllib
但仍然有同样的错误。我正在使用 Python 2.7.11。真的很感谢任何帮助
回答by elethan
A few things:
一些东西:
- As metioned in the comments,
urllib
is not installed throughpip
, it is part of the standard library, so you can just doimport urllib
without installation. - Python 3.x has a
urllib.request
module, but Python 2.x does not, as far as I know. The functionality that you are looking for from
urllib.request
is most likely contained inurllib2
(which is also part of the standard library), but you might be even better off usingrequests
, which probably does need to be installed throughpip
in your case:pip install requests
In fact, the
urllib2
documentation itself recommends that you use therequests
library "for a higher-level HTTP client interface" - but I am not sure what you wish to do, so it is hard to say what would be best for your particular use case.
- 正如评论中提到的,
urllib
不是通过 安装的pip
,它是标准库的一部分,所以你可以import urllib
不用安装。 urllib.request
据我所知,Python 3.x 有一个模块,但 Python 2.x 没有。您正在寻找的功能
urllib.request
很可能包含在urllib2
(它也是标准库的一部分)中,但您最好使用requests
,pip
在您的情况下可能需要安装它:pip install requests
事实上,
urllib2
文档本身建议您使用该requests
库“用于更高级别的 HTTP 客户端接口” - 但我不确定您希望做什么,因此很难说哪种方式最适合您的特定用例。