我正试图将我的web抓取程序从使用请求库转移到请求html库,以便在网页上呈现javascript。在导入模块时抛出此错误:
Traceback (most recent call last):
File "backend2.py", line 2, in <module>
import requests_html
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests_html.py", line 9, in <module>
import pyppeteer
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/__init__.py", line 30, in <module>
from pyppeteer.launcher import connect, launch, executablePath # noqa: E402
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/launcher.py", line 24, in <module>
from pyppeteer.browser import Browser
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/browser.py", line 15, in <module>
from pyppeteer.page import Page
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/page.py", line 20, in <module>
from pyppeteer.coverage import Coverage
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/coverage.py", line 15, in <module>
from pyppeteer.util import merge_dict
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/util.py", line 10, in <module>
from pyppeteer.chromium_downloader import check_chromium, chromium_executable
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/chromium_downloader.py", line 15, in <module>
from tqdm import tqdm
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tqdm/__init__.py", line 1, in <module>
from ._tqdm import tqdm
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tqdm/_tqdm.py", line 75, in <module>
mp_lock = mp.RLock() # multiprocessing lock
AttributeError: module 'multiprocessing' has no attribute 'RLock'
感谢您的帮助!
您使用的是Python 3.7,但请求html的github声明只支持Python 3.6(页面底部(。当我尝试使用Python 3.7时,我会遇到各种可怕的错误,但3.6运行良好。所以,我知道这似乎很奇怪,但请尝试使用3.6
即便如此,正如@georgexsh所说,在3.7中应该仍然有一个RLock
可以从multiprocessing
导入,所以看起来你的错误实际上可能是你的代码文件之一被称为multiprocessing.py
,或者你有自己的包multiprocessing
(所以你导入的是它,而不是你想要的模块(。