skip to Main Content

enter image description here

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


  1. What you need to do is only write import models, schemas and access your functions / classes from those files with models.<classname> or directly import them using import <classname> from models

    Login or Signup to reply.
  2. Vscode takes the workspace as the root directory, so you need to use the following code:

    from app import models,schemas
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search