Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reportMissingImports Python error but import works fine

Tags:

python

fastapi

When I install package with python and import it, I often get a missing imports message such as:

Import "fastapi" could not be resolvedPylancereportMissingImports

The imports always work perfectly fine, the fastapi example above will run a server and I can build an API without issue.

Can anyone explain why I am getting this error and how I could get rid of it?

like image 379
edwrdcodeu Avatar asked Apr 08 '26 13:04

edwrdcodeu


1 Answers

The causes could be:

  1. The name of the file - fastapi.py, if you name it in this could way you would get import errors. (Avoid filenames similar to package names)
  2. Installing on other environments. Most of the time it happens when you use both Conda and PiP on you system.
  3. If you run the code from VS Code, check if the same interpreter is selected.

Verify the installation:

$ pip list | grep fastapi

Suggestions:

OPT Virtual Environments to avoid these troubles.

Thank you!

like image 50
Mahimai Raja J Avatar answered Apr 11 '26 01:04

Mahimai Raja J



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!