-2

I installed all required libraries. Already having installed google, google-search, google-cloud, googlesearch-python, beautifulsoup4.But after all the things I got this error:

**Traceback (most recent call last):
  File "/usr/local/bin/sigit", line 9, in <module>
    from googlesearch import search
ImportError: cannot import name 'search' from 'googlesearch' (/usr/local/lib/python3.9/dist-packages/googlesearch/__init__.py)**

Please help me to solve this issue.

Tom McLean
  • 5,583
  • 1
  • 11
  • 36
Somraj
  • 23
  • 6
  • 3
    What exactly are you trying to do? Please read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Paul P Jun 18 '21 at 08:03

1 Answers1

2

That's really weird because imports that pypi.org recommends doesn't work at all. I dug into files of this library and this solution worked for me:

from googlesearch.googlesearch import GoogleSearch

search_engine = GoogleSearch()
response_object = search_engine.search('test')
print(response_object)

On pypi.org the latest version is not old, so it shouldn't be deprecated.

EDIT

Here's the exact example I figured out: https://pypi.org/project/google-search/. But is doesn't give any result. That's another weird thing. I recommend you to leave alone this libraries and find some good, free to use google search engine api.

blazej
  • 927
  • 4
  • 11
  • 21