# How to fix ImportError: cannot import name 'User' from partially initialized module 'models' (most likely due to a circular import)

Two modules import each other at the top level, so one of them is not finished when the other asks for a name. Break the cycle: move the shared name into a third module both import, or move one import inside the function that uses it, or `import models` and use `models.User` (attribute lookup happens at call time, after init). Restructuring beats the local-import band-aid.

## The exact error

```text
ImportError: cannot import name 'User' from partially initialized module 'models' (most likely due to a circular import)
```

## Fix it

1. Map the cycle: read the traceback's import chain (a imports b imports a).
   Expected: you see the loop

2. Best: extract the shared class/function into a third module both import.
   Expected: no cycle, imports clean

3. Quick: move one import inside the function using it, or switch to `import models` + `models.User`.
   Expected: works; revisit the structure later

## When this applies

the error says 'partially initialized module' and 'most likely due to a circular import'

## When this does NOT apply

the module truly lacks the name (typo) - then it is a plain ImportError

## Versions

any Python 3

## Why it happens

Python executes module top-level code on first import; a cycle means someone reads names from a half-executed module.

## Edge cases

TYPE_CHECKING imports dodge runtime cycles for annotations; `import x` plus attribute access is the idiomatic runtime dodge.

---

## Vectle citations

- Exact version: <https://vectle.com/skills/skl_8aX2B_QLd0YvTLmzquQ-gw/versions/skv_4Evx0cb7GN_CCB-1fj5sNA>
- Canonical HTML skill page: <https://vectle.com/skills/skl_8aX2B_QLd0YvTLmzquQ-gw>
- Current Markdown URL: <https://vectle.com/skills/skl_8aX2B_QLd0YvTLmzquQ-gw/markdown>

## Selected public attribution and original notices/references

```json
{
  "author": "issueatlas",
  "client": null,
  "notices_and_references": [
    "https://github.com/lasithadilshan/devfixhub/blob/HEAD/content/errors/python-importerror.mdx"
  ]
}
```
