I'm still a novice at Python, but I've learned quite a few things. However, I've finally hit a brick wall that I can't solve on my own.
I'm trying to run an application that utilizes a shared module that gets used between two applications. I've also been writing some tests in a separate folder at the same level. When I attempt to run app1 from the command line, it's throwing a 'no module named' error, referencing the shared module in the stack trace. When I run pytest
from the same location the tests that reference the shared module it executes without this error.
I've made sure that the relevant folders contain the __init__.py
file. I've also made sure I'm running the python3 ./App1/server.py
command from the appropriate location (proj1). My development uses virtualenv, and I've made sure it's active.
Folder structure used:
proj1
-- app1
-- __init__.py
-- app
-- __init__.py
-- some_flask_controller.py
-- server.py
-- app2
-- __init__.py
-- No other relevant details here
-- shared
-- __init__.py
-- some_file.py
-- tests
-- __init__.py
-- shared_tests
-- __init__.py
-- test_some_file.py
Stack when attempting to run python3 ./App1/server.py
:
Traceback (most recent call last):
File ".\App1\app.py", line 1, in <module>
from app import app
File "\Proj1\App1\app\__init__.py", line 10, in <module>
from app.some_flask_controller import mod_requests as request_module
File "\Proj1\App1\app\some_flask_controller.py", line 5, in <module>
from shared.some_file import some_class
ModuleNotFoundError: No module named 'shared'
I'm expecting either pytest
and python3 ./App1/server.py
to return this error, or both work. However, only pytest
is executing normally. Is there a reason for this?