ImportError: cannot import name 'GoogleSearch' from 'serpapi'
Fixes 'ImportError: cannot import name GoogleSearch from serpapi' by installing the correct package: pip install google-search-results (not pip install serpapi, which is a different library). Use when the SerpAPI Python client fails to import after installation. Not for API key or quota errors.
TL;DR
You installed the wrong package. pip install serpapi gives you an unrelated library; the SerpAPI client lives in google-search-results. Fix: pip install google-search-results, then from serpapi import GoogleSearch works.
The error
ImportError: cannot import name 'GoogleSearch' from 'serpapi'Fix it
- Uninstall the wrong package:
pip uninstall serpapi Success check: pip show serpapi reports the package is not installed.
- Install the correct SerpAPI client:
pip install google-search-resultsSuccess check: install completes with no errors.
- Verify the import:
python -c "from serpapi import GoogleSearch; print('ok')" Success check: prints ok with no ImportError.
When this applies
from serpapi import GoogleSearchraises ImportError right after installing what you thought was the SerpAPI client.- You ran
pip install serpapi(the wrong package).
When it does not apply
- The import works but API calls fail; that is an API key or quota problem, not a packaging problem.
- You are using the Node.js SerpAPI client (
serpapion npm is correct there). - The error names a different symbol than
GoogleSearch.
Compatibility
- Python 3.8+. Package
google-search-results(the official SerpAPI Python client). - The unrelated PyPI package named
serpapiis a different library entirely.
Variant phrasings
- ImportError cannot import name GoogleSearch from serpapi
- pip install serpapi wrong package
- serpapi python client import error
Why it happens
Two different libraries share a confusingly similar name on PyPI. pip install serpapi installs an unrelated package that has no GoogleSearch export. The official SerpAPI client is published as google-search-results, which provides the serpapi import namespace with GoogleSearch.
Edge cases
- If both packages are installed, uninstall
serpapifirst to avoid namespace shadowing. - In requirements files, pin
google-search-results, neverserpapi. - Source: https://github.com/serpapi/google-search-results-python/issues/63
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.