FastAPI error: Cannot import name 'FastApi' from 'fastapi'

Question:

I want to use FastAPI. I installed it using pip, and when I am adding it to my project like that:

from fastapi import FastApi 

and running it, Iam getting the error:

cannot import name 'FastApi' from 'fastapi' (C:UsersxxxPycharmProjectsMyBankvenvlibsite-packagesfastapi__init__.py).

Can someone help me?

Asked By: tsofia

||

Answers:

That should be as follows (with "API" being capitalised at the end):

from fastapi import FastAPI

Please have a look at the documentation.

Answered By: Chris

Might come from the fact that the name of your python file is actually fastapi and python is messed up by the fact that import is primarily looking at the current folder to import files then the libs.

meaning that if you have a file named : fastapi.py python will think that import fastapi means import the fastapi.py file from the current working dir and will fail.

Answered By: guignol

Try

from fastapi import FastAPI
Answered By: Akshay Raut
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.