Python 2.7.10 错误“从 urllib.request 导入 urlopen"没有模块命名请求 [英] Python 2.7.10 error "from urllib.request import urlopen" no module named request
问题描述
我从 github
打开了 python 代码.我假设它是 python2.x
并在我尝试运行它时出现上述错误.从阅读中我看到 Python 3 贬低了 urllib
本身,并用包括 urllib.request
在内的许多库替换了它.
看起来代码是用 python 3 编写的(感谢知道的人的确认.)在这一点上,我不想转移到 Python 3 - 我还没有研究它会对我现有的代码做什么.
认为Python 2
应该有一个urllib
模块,我在Google 上搜索(使用python2 urllib 下载")并没有找到.(它可能隐藏在许多答案中,因为 urllib
包含下载功能.)我查看了我的 Python27/lib
目录,但没有在那里看到它.我可以获得在 Python27
上运行的这个模块的版本吗?地点和方式?
尝试使用 urllib2:
https://docs.python.org/2/library/urllib2.html>
这一行应该可以代替 urlopen:
from urllib2 import urlopen
在 Macbook Pro 上用 Python 2.7 测试
尝试发布指向相关 git 的链接.
I opened python code from github
. I assumed it was python2.x
and got the above error when I tried to run it. From the reading I've seen Python 3 has depreciated urllib
itself and replaced it with a number of libraries including urllib.request
.
It looks like the code was written in python 3 (a confirmation from someone who knows would be appreciated.) At this point I don't want to move to Python 3 - I haven't researched what it would do to my existing code.
Thinking there should be a urllib
module for Python 2
, I searched Google (using "python2 urllib download") and did not find one. (It might have been hidden in the many answers since urllib
includes downloading functionality.) I looked in my Python27/lib
directory and didn't see it there.
Can I get a version of this module that runs on Python27
? Where and how?
Try using urllib2:
https://docs.python.org/2/library/urllib2.html
This line should work to replace urlopen:
from urllib2 import urlopen
Tested in Python 2.7 on Macbook Pro
Try posting a link to the git in question.
这篇关于Python 2.7.10 错误“从 urllib.request 导入 urlopen"没有模块命名请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!