Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why i can't import BaseModel from Pydantic?

enter code hereI try to import pydantic (1.8.1 ver.) library.

When i try import BaseModel from pydantic I get error. I try to import like this from pydantic import BaseModel

Output:

ImportError: cannot import name 'BaseModel' from partially initialized module 'pydantic' (most likely due to a circular import) (D:\temp\main.py)

This is my code:

from pydantic import BaseModel  
from datetime import datetime
from datetime import date
from typing import List, Dict

class CurrencyRequest(BaseModel):

    base: str = "EUR"
    symbols: List[str]
    start_at: date = None
    end_at: date = None

    def __str__(self):
        return """
        Dates range: {start} - {end}
        Base currency: {base}
        Different currencies: {curr}
        """.format(
            start=self.start_at.strftime("%Y-%m-%d") if self.start_at is not None else "...",
            end=self.end_at.strftime("%Y-%m-%d") if self.end_at is not None else "...",
            base=self.base,
            curr=self.symbols
        )

This is link to photo with error

Thanks for all answers.

like image 485
Kuba Avatar asked Oct 17 '25 02:10

Kuba


1 Answers

Probably you have a package or a module with name "pydantic" in the root path.

EDIT: on the screenshot of the error you have "pydantic" folder. Try to rename it

like image 126
Artur Shiriev Avatar answered Oct 19 '25 16:10

Artur Shiriev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!