ImportError : no module named requests
ImportError : no module named requests
我正在尝试使用 BeautifulSoup 从天气网站检索数据。网站示例:
<channel>
<title>2 Hour Forecast</title>
<source>Meteorological Services Singapore</source>
<description>2 Hour Forecast</description>
<item>
<title>Nowcast Table</title>
<category>Singapore Weather Conditions</category>
<forecastIssue date="18-07-2016" time="03:30 PM"/>
<validTime>3.30 pm to 5.30 pm</validTime>
<weatherForecast>
<area forecast="TL" lat="1.37500000" lon="103.83900000" name="Ang Mo Kio"/>
<area forecast="SH" lat="1.32100000" lon="103.92400000" name="Bedok"/>
<area forecast="TL" lat="1.35077200" lon="103.83900000" name="Bishan"/>
<area forecast="CL" lat="1.30400000" lon="103.70100000" name="Boon Lay"/>
<area forecast="CL" lat="1.35300000" lon="103.75400000" name="Bukit Batok"/>
<area forecast="CL" lat="1.27700000" lon="103.81900000" name="Bukit Merah"/>`
</weatherForecast>
<channel>
我想检索下午 3.30 到 5.30,介于 validTime
之间
检查页面中的元素后,我发现 3.30 pm 到 5.30 pm 在 span 元素中的 "class = Text" 中:
sample of how the weather data looks like
这是我使用 Python 的代码:
import requests
from bs4 import BeautifulSoup
import urllib3
r = requests.get('http://www.nea.gov.sg/api/WebAPI/?
dataset=2hr_nowcast&keyref=781CF461BB6606AD907750DFD1D07667C6E7C5141804F45D')
soup = BeautifulSoup(r.content, "xml")
soup.find('validTime').string
但是,当我 运行 代码时,我收到一条错误消息 "ImportError : No module name requests"
我已经下载并放置了请求in the Lib within Python27 folder on my C drive
我还使用 "pip list" 检查了我是否安装了请求,这就是我得到的:
beautifulsoup4 <4.4.1>
httplib2 <0.9.2>
lxml <3.6.0>
pip <8.1.2>
requests <2.10.0>
...
如您所见,requests 已经下载到我的 C 盘 (C:\Python27\Scripts)
为什么我在命令提示符下出现错误?
首先说一下我的一些困惑。
在您的屏幕截图中:in the Lib within Python27 folder on my C drive。
首先,文件夹"ensurepip"意味着它会帮助你安装pip,但是你没有"site-packages"目录这意味着pip还没有安装在python版本。
其次,文件夹"python2"已经存在。它为什么在那里?
三、如果你已经用pip命令"pip install requests"安装了"requests",为什么还要复制"requests",你的"requests"是从哪里来的?
解决方案失败。
1.uninstall 你的 python.
2.install python "C:\Python27" 中的 2.7.12 msi 将帮助您自动安装 pip。
3.check"C:\Python27\Lib\site-packages\pip*",如果不存在,说明你安装错误
4.add "C:\Python27;C:\Python27\Scripts" 在您的系统环境路径中。
5."python" 在 cmd 工具中检查您的 python 版本是否为“2.7.12”。
6."pip install requests"在cmd工具里。
7.check "C:\Python27\Lib\site-packages\requests".
如果一切都正确完成,您将成功导入请求。
安装 link 是 https://www.python.org/downloads/release/python-2712/
我按照我的错误解决了这个问题
>>import requests
"Traceback (most recent call last):
File "<pyshell#175>", line 1, in <module>
import requests
ImportError: No module named 'requests' "
下载请求存储库
https://github.com/kennethreitz/requests
将请求目录复制到 python 路径 [例如。 C:\Users\UserName\AppData\Local\Programs\Python\Python35-32]
我正在尝试使用 BeautifulSoup 从天气网站检索数据。网站示例:
<channel>
<title>2 Hour Forecast</title>
<source>Meteorological Services Singapore</source>
<description>2 Hour Forecast</description>
<item>
<title>Nowcast Table</title>
<category>Singapore Weather Conditions</category>
<forecastIssue date="18-07-2016" time="03:30 PM"/>
<validTime>3.30 pm to 5.30 pm</validTime>
<weatherForecast>
<area forecast="TL" lat="1.37500000" lon="103.83900000" name="Ang Mo Kio"/>
<area forecast="SH" lat="1.32100000" lon="103.92400000" name="Bedok"/>
<area forecast="TL" lat="1.35077200" lon="103.83900000" name="Bishan"/>
<area forecast="CL" lat="1.30400000" lon="103.70100000" name="Boon Lay"/>
<area forecast="CL" lat="1.35300000" lon="103.75400000" name="Bukit Batok"/>
<area forecast="CL" lat="1.27700000" lon="103.81900000" name="Bukit Merah"/>`
</weatherForecast>
<channel>
我想检索下午 3.30 到 5.30,介于 validTime
之间检查页面中的元素后,我发现 3.30 pm 到 5.30 pm 在 span 元素中的 "class = Text" 中:
sample of how the weather data looks like
这是我使用 Python 的代码:
import requests
from bs4 import BeautifulSoup
import urllib3
r = requests.get('http://www.nea.gov.sg/api/WebAPI/?
dataset=2hr_nowcast&keyref=781CF461BB6606AD907750DFD1D07667C6E7C5141804F45D')
soup = BeautifulSoup(r.content, "xml")
soup.find('validTime').string
但是,当我 运行 代码时,我收到一条错误消息 "ImportError : No module name requests"
我已经下载并放置了请求in the Lib within Python27 folder on my C drive
我还使用 "pip list" 检查了我是否安装了请求,这就是我得到的:
beautifulsoup4 <4.4.1>
httplib2 <0.9.2>
lxml <3.6.0>
pip <8.1.2>
requests <2.10.0>
...
如您所见,requests 已经下载到我的 C 盘 (C:\Python27\Scripts)
为什么我在命令提示符下出现错误?
首先说一下我的一些困惑。
在您的屏幕截图中:in the Lib within Python27 folder on my C drive。
首先,文件夹"ensurepip"意味着它会帮助你安装pip,但是你没有"site-packages"目录这意味着pip还没有安装在python版本。
其次,文件夹"python2"已经存在。它为什么在那里?
三、如果你已经用pip命令"pip install requests"安装了"requests",为什么还要复制"requests",你的"requests"是从哪里来的?
解决方案失败。
1.uninstall 你的 python.
2.install python "C:\Python27" 中的 2.7.12 msi 将帮助您自动安装 pip。
3.check"C:\Python27\Lib\site-packages\pip*",如果不存在,说明你安装错误
4.add "C:\Python27;C:\Python27\Scripts" 在您的系统环境路径中。
5."python" 在 cmd 工具中检查您的 python 版本是否为“2.7.12”。
6."pip install requests"在cmd工具里。
7.check "C:\Python27\Lib\site-packages\requests".
如果一切都正确完成,您将成功导入请求。
安装 link 是 https://www.python.org/downloads/release/python-2712/
我按照我的错误解决了这个问题
>>import requests
"Traceback (most recent call last):
File "<pyshell#175>", line 1, in <module>
import requests
ImportError: No module named 'requests' "
下载请求存储库 https://github.com/kennethreitz/requests
将请求目录复制到 python 路径 [例如。 C:\Users\UserName\AppData\Local\Programs\Python\Python35-32]