I'm new to Python, and I try to structure my Python application.
Given the following directory structure:
app
┣ lexer
┃ ┣ token
┃ ┃ ┣ token.py
┃ ┃ ┣ type.py
┃ ┃ ┗ __init__.py
┃ ┗ __init__.py
┣ test
┃ ┣ lexer
┃ ┃ ┣ token
┃ ┃ ┃ ┣ test_token.py
┃ ┃ ┃ ┗ __init__.py
┃ ┃ ┗ __init__.py
┃ ┣ test_app.py
┃ ┗ __init__.py
┗ app.py
Right now, the application is executed using the following command:
pyhton -m app
When I try to execute the application using
python -m .\app.py
The following error is raised:
Relative module names not supported.
Unit tests are being executed using:
python -m unittest
This works fine and without issues.
Now, I'm trying to use the import the token / type.py
file in the app.py
file.
The contents of this file are:
from enum import Enum, unique
@unique
class Type(Enum):
UNKNOWN = 1
EOF = 2
The following import statement is added in the app.py
file:
from app.lexer.token.type import Type
Running the application right now yields the following error:
Traceback (most recent call last):
File "C:\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\DEV\DEMO.ONE\app\app.py", line 17, in <module>
from app.lexer.token.type import Type
File "C:\DEV\DEMO.ONE\app\app.py", line 17, in <module>
from app.lexer.token.type import Type
ModuleNotFoundError: No module named 'app.lexer'; 'app' is not a package
Any ideas on how this can be fixed?