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

Question:

I’m trying to repurpose some old code I found from 3 years ago, where it grabs text using an OCR, then Googles what it found.

In the original code, it imports the google package using from google import google, and then using google.search(). However, when I try it today, I’m getting this error traced to the line the package gets imported.

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

Now, I’m assuming that at the time, this worked fine, but considering Google is Google, the process I need to follow today is different from what it was 3 years ago. My guess is that googlesearch should be the package I need to use, or that I need to define the location google is installed to in the code, but I’m not exactly sure what needs to be done to make it work, even after searching for the issue for hours. Any tips and suggestions would help tons.

Asked By: Tasos500

||

Answers:

I would install googlesearch using python3 -m pip install googlesearch-python

Then the function is simple to call.

from googlesearch import search
search("foo")
Answered By: MegaEmailman