I'm new to Docker. When I am running my docker container, the last line in the Dockerfile is the following:
CMD ["python3", "./poses/server/server_multithreaded.py"]
In the server_multithreaded.py file described above, I am importing another file, as seen below:
from poses.poseapp.poseapp_sockets import PoseAppWSockets
When I run container using the command docker run -p 8089:8089 zoheezus/capstone
I get the following error:
Traceback (most recent call last):
File "./poses/server/server_multithreaded.py", line 18, in <module>
from poses.poseapp.poseapp_sockets import PoseAppWSockets
ImportError: No module named 'poses'
From what I understand, the 'poses' directory is not accessible or I am not accessing it the right way. What do I need to do for server_multithreaded.py to be able to access the other files when I run it?
The file structure of the project is the following:
Python won't add current working path into module search path, it will just add top level script's path into search path, of course
PYTHONPATH
,sys path
etc. also be searched.For your case, the current working path
/usr/pose_recognizer
won't be searched, only/usr/pose_recognizer/poses/server
will be searched. So, definitely, it won't find module named 'poses'.To make it work for you, give you some options:
Option 1: Execute the
server_multithreaded.py
as module:Option 2: Change
sys.path
inserver_multithreaded.py
as next beforefrom poses.poseapp.poseapp_sockets import PoseAppWSockets
:Option 3: Change
PYTHONPATH
in dockerfile: