I have the following project tree:
├── Dockerfile
├── modules
│ ├── __init__.py
│ ├── scripts_A
│ │ ├── file_1.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ └── scripts_B
│ ├── file_2.py
│ ├── __init__.py
│ └── __pycache__
The Dockerfile:
FROM python:3.7-slim-buster
WORKDIR /app
RUN apt-get update
RUN mkdir /modules
COPY script.py /app/
COPY ./modules/* /app/modules/
RUN export PYTHONPATH=/app/
RUN dir
CMD [ "python", "script.py" ]
and the files content is as follows:
#script.py
from modules.scripts_B.file_2 import *
def hello_world():
external_print()
if __name__ == '__main__':
hello_world()
#file_1.py
def my_print():
print("Hi")
#file_2.py
from modules.scripts_A.file_1 import *
def external_print():
my_print()
If I launch the python script.py on my pc everything is correct, but when I run the same script via docker it raises an error:
Traceback (most recent call last):
File "script.py", line 2, in <module>
from modules.scripts_B.file_2 import *
ModuleNotFoundError: No module named 'modules.scripts_B'
Does anybody see where the bug origins from?
UPD
I added __init__, nothing has changed.
I added inits files everywhere problem is still present