Python 3.2 无法导入 urllib2(导入错误:没有名为 urllib2 的模块)
问题描述:
我使用的是 Windows,但出现错误:
I am using Windows, and I get the error:
ImportError: No module named urllib2
我认为这个是适用于 Linux 的解决方案.但是如何在 Windows 中进行设置?
I think this is the solution for Linux. But how to set this in Windows?
我使用的是 Python 3.2,但在 LiB 文件夹中看不到 urllib2
.
I am using Python 3.2 and I am not able see urllib2
there in the LiB folder.
答
在 python 3 中,urllib2 被合并到 urllib 中.另见另一个堆栈溢出问题和urllib PEP 3108.
In python 3 urllib2 was merged into urllib. See also another Stack Overflow question and the urllib PEP 3108.
要使 Python 2 代码在 Python 3 中工作:
To make Python 2 code work in Python 3:
try:
import urllib.request as urllib2
except ImportError:
import urllib2