In my virtual environment, I am trying to import "models.py" file into main.py
for that I tried:
""" from . import models, schemas """.
but even though models.py and main.py both file are at same levels I am unable to import it is giving this error:
"""ImportError: cannot import name ‘models’ from ‘app.routers’ (unknown location)"""
2
Answers
What you need to do is only write
import models, schemas
and access your functions / classes from those files withmodels.<classname>
or directly import them usingimport <classname> from models
Vscode takes the workspace as the root directory, so you need to use the following code: