【问题标题】:ImportError: cannot import name 'search' from 'google' (unknown location)ImportError:无法从“google”(未知位置)导入名称“search”
【发布时间】:2020-12-14 06:08:35
【问题描述】:

我正在尝试重新利用我在 3 年前找到的一些旧代码,它使用 OCR 抓取文本,然后用 Google 搜索它找到的内容。

在原始代码中,它使用from google import google 导入google 包,然后使用google.search()。但是,当我今天尝试时,我发现此错误可追溯到导入包的行。

ImportError: cannot import name 'google' from 'google' (unknown location)

现在,我假设当时它运行良好,但考虑到 Google 就是 Google,我今天需要遵循的流程与 3 年前不同。我的猜测是googlesearch 应该是我需要使用的包,或者我需要在代码中定义安装google 的位置,但我不确定需要做什么才能使其工作,即使在搜索了几个小时之后。任何提示和建议都会有所帮助。

【问题讨论】:

    标签: python python-3.x google-api google-search


    【解决方案1】:

    我会使用 python3 -m pip googlesearch-python 安装 googlesearch

    那么函数调用就简单了。

    from googlesearch import search
    search("foo")
    

    【讨论】:

    • AttributeError: module 'googlesearch' has no attribute 'search' 在预建名称冲突的情况下:尝试只安装 google 并导入 search python -m pip install google
    猜你喜欢
    • 1970-01-01
    • 2019-02-26
    • 2021-02-06
    • 2021-03-21
    • 2020-09-08
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多