ImportError: cannot import name 'HTMLSession' from 'requests_html'
ImportError: cannot import name 'HTMLSession' from 'requests_html'
当我尝试使用新模块requests_html使用其网站的示例时,我发现控制台在标题中显示信息。
- 我已经使用
pip install requests_html
成功安装了 requests_html
- 我已将 python 更新为 python3.7(64 位)
控制台消息:
Traceback (most recent call last):
File "C:/Users/owlish/PycharmProjects/python34/requests.py", line 2, in <module>
from requests_html import HTMLSession
File "C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py", line 10, in <module>
import requests
File "C:\Users\owlish\PycharmProjects\python34\requests.py", line 2, in <module>
from requests_html import HTMLSession
ImportError: cannot import name 'HTMLSession' from 'requests_html' (C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py)
代码:
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://python.org/')
我希望它能正常工作,就像示例一样 https://html.python-requests.org/。
在 AhmedHawary 的帮助下,我找到了 error:I 有一个名为 requests.py 的文件的原因,该文件与 关键字冲突。我重命名文件名后它工作正常
当我尝试使用新模块requests_html使用其网站的示例时,我发现控制台在标题中显示信息。
- 我已经使用
pip install requests_html
成功安装了 requests_html
- 我已将 python 更新为 python3.7(64 位)
控制台消息:
Traceback (most recent call last):
File "C:/Users/owlish/PycharmProjects/python34/requests.py", line 2, in <module>
from requests_html import HTMLSession
File "C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py", line 10, in <module>
import requests
File "C:\Users\owlish\PycharmProjects\python34\requests.py", line 2, in <module>
from requests_html import HTMLSession
ImportError: cannot import name 'HTMLSession' from 'requests_html' (C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py)
代码:
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://python.org/')
我希望它能正常工作,就像示例一样 https://html.python-requests.org/。
在 AhmedHawary 的帮助下,我找到了 error:I 有一个名为 requests.py 的文件的原因,该文件与 关键字冲突。我重命名文件名后它工作正常