2

我正在尝试将我的网络抓取程序从使用 requests 库转移到 requests-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'

任何帮助表示赞赏!

4

1 回答 1

1

您使用的是 Python 3.7,但 requests-html 的 github 声明仅支持 Python 3.6(页面底部)。当我尝试使用 Python 3.7 时遇到各种可怕的错误,但 3.6 可以正常工作。所以,我知道这似乎很奇怪,但请尝试使用 3.6

即便如此,正如@georgexsh 所说,在 3.7 中仍然应该有一个RLock可用于导入的multiprocessing,所以看起来你的错误实际上可能是你的代码文件之一被调用multiprocessing.py或者你有自己的包被调用multiprocessing(所以你正在导入它而不是你想要的模块)。

于 2018-11-27T09:58:06.683 回答