0

Here's my directory structure:

app
   -Folder1
       -class-container.py
       -queries.py
       -script.py
   -Folder2
   -Folder3
   -main.py

In my class-container file I import the SQL queries from queries.py with from Folder1.queries import sql_queries When I import and use the class in main.py everything runs smoothly. But when I do the same from script.py I get a ModuleNotFoundError... no module named Folder1. I've tried relative imports and changing it to from queries import sql_queries but every time I change it, it breaks one or the other. Any insight would be valuable. Thanks!

Adam Roman
  • 97
  • 5
  • For a relative import, the syntax would be `from .queries import sql_queries` (take note of the period). – Kyle Willmon May 06 '19 at 14:16
  • Also, it's helpful to know if `script.py` is purely a script or if there are any other python files that import it as a module (with some form of `import script`) – Kyle Willmon May 06 '19 at 14:16
  • I tried the from .queries import sql_queries but it breaks when I run it from the script.py. Specifically, I get an ImportError attempted relative import with no known parent package. Also, the script.py is purely a script, it isn't imported from any other python files. – Adam Roman May 06 '19 at 14:21
  • 1
    Have you read [this answer](https://stackoverflow.com/a/14132912/11443248) regarding Python relative imports – Kyle Willmon May 06 '19 at 14:27

0 Answers0