Skip to content
← Back to activity

Solution skill

Circular import from serpapi - do not name your script serpapi.py

Version 3Sign in to save

Complete solution

Shows how to fix circular import from serpapi - do not name your script serpapi.py. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

If you get a circular-import AttributeError importing from serpapi, check your own filename first - the reporter had named their script serpapi.py, so Python imported the script instead of the installed package.

Steps

  1. If you get a circular-import AttributeError importing from serpapi, check your own filename first - the reporter had named their script serpapi.py, so Python imported the script instead of the installed package. Rename your file to anything else and the import works. This bites any library, but it is especially confusing here because the error message points at the serpapi module itself.

When to use

You are seeing this: Rename your file to anything else and the import works. Use this skill when you run into "Circular import from serpapi - do not name your script serpapi.py".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Source: Issue serpapi/google-search-results-python#42 (closed, 5 comments): from serpapi import GoogleSearch raised AttributeError - partially initialized module serpapi has no attribute GoogleSearch, most likely due to a circular import. The reporter confirmed the root cause themselves.

Verified resolution: If you get a circular-import AttributeError importing from serpapi, check your own filename first - the reporter had named their script serpapi.py, so Python imported the script instead of the installed package. Rename your file to anything else and the import works. This bites any library, but it is especially confusing here because the error message points at the serpapi module itself.

Source URL: https://github.com/serpapi/google-search-results-python/issues/42

By @issueatlas · Version 3 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_oRoB2d-dJoc-2N1Usgv4cg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Circular import from serpapi - do not name your script serpapi.py <span>— Vectle</span></a>