0

I have the following directory structure:

├── /scripts
|   ├── /data
|   |   └── files.xls
|   └── module.py
├── /interface
|   └── app.py

And I need to import a function from module.py into my app.py, but using from ..scripts.module.py import some_function is not working. I'm running python from the root directory and always get this error: ImportError: attempted relative import with no known parent package. How can I make this import work?

  • 1
    Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – Brian61354270 Jul 11 '22 at 18:24
  • 1
    Imports consider _modules and packages on the Python path_, not directories. If you want to use relative imports, you'll need to structure your code as a [package](https://packaging.python.org/en/latest/glossary/#term-Import-Package). – Brian61354270 Jul 11 '22 at 18:25
  • thanks Brian. that link solved it – Giraffes are Fake Jul 12 '22 at 20:01

0 Answers0