Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入urllib.request,导入错误:没有名为request的模块_Python_Importerror - Fatal编程技术网

Python 导入urllib.request,导入错误:没有名为request的模块

Python 导入urllib.request,导入错误:没有名为request的模块,python,importerror,Python,Importerror,我试图在窗口10的PyCharm 4.5.4上导入Python2.7.10的urllib.request,但出现错误“ImportError:没有名为request的模块”。我也遇到了同样的错误,并用谷歌搜索解决了它。 urlib.request适用于Python 3.0 您可以使用以下代码: import urllib urllib.urlopen(url) 如果您有windows计算机,请使用>Path\easy\u install.exe请求,其中easy\u install可以在Pyt

我试图在窗口10的PyCharm 4.5.4上导入Python2.7.10的urllib.request,但出现错误“ImportError:没有名为request的模块”。我也遇到了同样的错误,并用谷歌搜索解决了它。
urlib.request
适用于Python 3.0

您可以使用以下代码:

import urllib
urllib.urlopen(url)

如果您有windows计算机,请使用>
Path\easy\u install.exe
请求,其中
easy\u install
可以在Python*\Scripts文件夹中找到(如果已安装)。(注意Path\easy\u install.exe就是一个例子,我的是C:\Python32\Scripts\easy\u install.exe)

如果您没有“轻松安装”功能,并且正在windows计算机上运行,您可以在此处获得:

如果要手动将库添加到windows计算机,可以下载压缩库,解压缩它,然后将其放入python路径的Lib文件夹中

您需要先安装
pip
,然后使用pip安装
django-request

pip install django-request
还安装,

python setup.py install
然后导入

from urllib.request import urlopen
有用的提示:检查


urllib.request模块已被弃用。。 只用

对于你的功能,如果你之前写过

urllib.request.urlretrieve
现在你只要写

urllib.urlretrieve

尝试在Python3中使用此选项

try:
    x = urllib.request.urlopen('https://www.google.com/search?q=test')
    print(x.read())

except Exception as e:
    print(str(e))

如果尝试使用python 2运行python 3文件,就会出现此错误。

有时可能会发生此错误,通常在Linux环境中。您已经安装了2.x和3.x版本的python

因此,在这种情况下,如果您使用命令python“file.py”

默认情况下,python 2.x将运行该文件

因此,使用命令python3“file.py”

我正面临着这个问题。也许它能解决某人的问题

try:
    x = urllib.request.urlopen('https://www.google.com/search?q=test')
    print(x.read())

except Exception as e:
    print(str(e))