serpapi / google-search-results-python

Google Search Results via SERP API pip Python Package
MIT License
600 stars 97 forks source link

ImportError: cannot import name 'GoogleSearch' from 'serpapi' #63

Closed nazib closed 11 months ago

nazib commented 12 months ago

After creating a subscriber account in serpapi, I have been given an API key. I Installed the "pip install google-search-results "

but whenever I tried to run my django app I get this error:

File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/threading.py", line 870, in run self._target(*self._args, self._kwargs) File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, *kwargs) File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run autoreload.raise_last_exception() File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception raise _exception[1] File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/core/management/init.py", line 394, in execute autoreload.check_errors(django.setup)() File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(args, kwargs) File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/apps/registry.py", line 116, in populate app_config.import_models() File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/django/apps/config.py", line 269, in import_models self.models_module = import_module(models_module_name) File "/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 843, in exec_module File "", line 219, in _call_with_frames_removed File "/Users/MyProjects/topsearch/topsearch/searchapp/models.py", line 3, in from serpapi import GoogleSearch ImportError: cannot import name 'GoogleSearch' from 'serpapi' (/Users/nazibabdullah/opt/miniconda3/envs/topsearch/lib/python3.8/site-packages/serpapi/init.py)

medero commented 12 months ago

Are you still getting it? Have you tried Python 3.7?

At one point I think I got the same error but then I just re-did my requirements.txt and reinstalled it via pip, restarted docker containers.. I also had to downgrade to Python 3.7 because was running into a segmentation fault with 3.8 and my specific docker instance - lemme know how it goes... curious

And if you can provide info on if you have a Docker setup or your requirements.txt that'd be great

nazib commented 11 months ago

yep working now. Thanks so much

medero commented 11 months ago

Nice! For documentation-sake, what fixed it? Did you downgrade to Python 3.7, or?

zeptoon commented 11 months ago

Same issue, doesn't work out of the box (Python 3.9.0)

ranfysvalle02 commented 11 months ago

I ran into the same issue, was able to work around it by:

import serpapi

and then doing

serpapi.search(params_go_here) instead of GoogleSearch(params_go_here)
2282588541a commented 7 months ago

same issue!!!

m00t13 commented 6 months ago

The actual fix is to pip install google-search-results

Shahidsaheb commented 5 months ago

I also got the same issue. Before, I just installed "pip install serpapi" and then tried to import "GoogleSearch", which gave me the same error. Then I installed "pip install google-search-results" and tried again. It resolved the issue & I got the result.

midniteclub commented 5 months ago

I ran into the same issue, was able to work around it by:

import serpapi

and then doing

serpapi.search(params_go_here) instead of GoogleSearch(params_go_here)

Tried to use SerpApi with GoogleSearch but still wasn't able to get things working with 'pip install google-search-results'. Setting 'results = serpapi.search(params)' and then converting the 'results' object to a pandas dataframe worked for me.

KamiTzayig commented 4 months ago

i there no other way around this? im using python 3.12.4 and cant get this to work. would prefer not to do any hacks and import it normally error: ImportError: cannot import name 'GoogleSearch' from 'serpapi' (unknown location)

i did pip install google-search-results like documented

ZiiS-ND commented 4 months ago

I use this import from serpapi.google_search import GoogleSearch After the pip install google-search-results

And it works normally.

Python 3.8.6 serpapi 0.1.5 google-search-results 2.4.2

thisisvk45 commented 4 months ago

same issue!!!