ValueError: attempted relative import beyond top-level package (Python)

Viewed 12

Okay so I have seen lots of different stackoverflow answers about how you need to use relative imports. Which I am doing - Before I put the dots I was getting 'module not found' errors.

│   bs-url.bat
│
├───batch_processing
│   │   .env.dist
│   │   .env.local
│   │   convert_url.py
│   │   __init__.py
|
├───models
│   │   models.py
│   │   __init__.py

So from the top directory I am running bs-url.bat, which simply runs batch_processing/convert_url.py with arguments. From inside there I am trying to import from models. I have tried:

from .. models.models import create_model

If I have one dot or three dots VSCode underlines as an error. But using the above import I get the error message in the title:

    from .. models.models import create_model
ValueError: attempted relative import beyond top-level package

As far as I have read up on relative imports this should work. So I dont understand why Im getting the error.

If I use the import in a .py file in the same directory as the bs-url.bat file then it would work.

Any help or insights?

0 Answers
Related