question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] Pydantic ImportError: cannot import name 'Field'

See original GitHub issue

First, thanks for FastAPI! Great work here and this is fast indeed! We are thinking of using it instead of our actual framework.

Description

Is this normal I can’t import the class Field from Pydantic?

Additional context

This code:

from pydantic import BaseModel, Field

class BackbonePrefix(BaseModel):
    mask: int = Field(ge=0, le=31)

…gives me this error:

ImportError: cannot import name 'Field'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tiangolocommented, Apr 10, 2020

Thanks for the help here everyone! 👏 🙇

Thanks for reporting back and closing the issue @insideshell 👍

For everyone else, FastAPI has support for Pydantic version 1.0.0 and above since version 0.44.0, so, make sure you update your FastAPI version and upgrade the Pydantic version as well ✔️

2reactions
duz-sgcommented, Dec 16, 2019

@duz-sg You can import it by these ways in pydantic v1.x.

from pydantic.networks import EmailStr

or

from pydantic import EmailStr

Thanks, I saw this fix in another post, will try to fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why i can't import BaseModel from Pydantic? - Stack Overflow
ImportError: cannot import name 'BaseModel' from partially initialized module 'pydantic' (most likely due to a circular import) ...
Read more >
ImportError: cannot import name 'ModelField' from 'pydantic ...
I run it inside an “env” as described in the README. The first problem was a missing dependency, but I could fix this...
Read more >
ImportError: cannot import name 'Schema' from 'pydantic' - done
It appears that prodigy breaks when pydantic>=1.8 . This is because the pydantic. fields.
Read more >
How to Fix : “ImportError: Cannot import name X” in Python?
You can solve the “ ImportError : Cannot import name X” Error by resolving the circular dependencies. You can do that either by...
Read more >
tiangolo/fastapi - Gitter
import pydantic from typing import List, ForwardRef # Without this line: ... get an error: ImportError: cannot import name 'models' from 'fastapi_users' (....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found