0

For months I have tried to import my own classes from a subdirectory in Python, but I am yet to succeed in this task. It is a no-brainer in any other language, even C++.

Here is my app.py:

# my classes
from .classes.questions import Questions
from .classes.question import Question
from .classes.user import User
# ...

Here is my Questions class:

from question import Question
class Questions:
    def __init__(self):
        self.questions = []

Here is my directory structure:

.
├── app.py
├── classes
│   ├── question.py
│   ├── questions.py
│   └── user.py

Note 1: I have tried CamelCase naming for the modules.

Note 2: I have tried having init.py in any and all folders, but I'm on Python 3.8

The error message that is menacing me:

While importing 'app', an ImportError was raised.

in any and every environment.

I can import modules/classes with no issue as long as they are in the same folder as app.py.

How may I succeed in this daunting task?

ni-eminen
  • 35
  • 5
  • How are you launching it? What is "any and every environment"? – Keith Feb 20 '22 at 19:21
  • At the moment I am creating a Flask app and deploying it on heroku. But this has been an issue before with a tkinter app too. It works if I add the subdir to path with the os module, but then it doesn't work on Heroku, as it seems I can't create a relative link. – ni-eminen Feb 20 '22 at 20:32

0 Answers0