3

I have an Angular-Flask application that I'm trying to Dockerize. One of the Python files used is a file called trial.py. This file uses a module called _trial.pyd. When I run the project on local everything works fine. However, when I dockerize using the following code and run, it gives me error "Module _trial not found".

FROM node:latest as node
COPY . /APP
COPY package.json /APP/package.json
WORKDIR /APP
RUN npm install
RUN npm install -g @angular/[email protected]
CMD ng build --base-href /static/

FROM python:3.6
WORKDIR /root/
COPY --from=0 /APP/ .
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["app.py"]

Where am I going wrong? Do I need to change some path in my dockerfile?

EDIT: Directory structure:

  • APP [folder with src Angular files]
  • static [folder with js files]
  • templates [folder with index.html]
  • _trial.pyd
  • app.py [Starting point of execution]
  • Dockerfile
  • package.json
  • requirements.txt
  • trial.py

app.py calls trial.py (successfully).

trial.py needs _trial.pyd. I try to call it using import _trial.

It works fine locally, but when I dockerize it, i get the following error message:

Traceback (most recent call last):

File "app.py", line 7, in

from trial import *

File "/root/trial.py", line 15, in

import _trial

ModuleNotFoundError: No module named '_trial'

The commands run are:

docker image build -t prj .

docker container run --publish 5000:5000 --name prj prj

UPDATE It is able to recognize other .py files but not .pyd module.

2 Answers 2

3

Solved it! The issue was that I was using .pyd files in a Linux container. However, it seems that Linux doesn't support .pyd files. This is why it was not able to detect the _trial.pyd module. I had to generate a shared object (.so) file (i.e. _trial.so) and it worked fine.

EDIT: The .so file was generated on a Linux system by me. Generating .so on Windows and then using it in a Linux container gives "invalid ELF header" error.

Sign up to request clarification or add additional context in comments.

Comments

2

I think this could be due to the following reasons

Path

Make sure the required file is in the pythonpath. It sounds like you have done that so probably not this one.

Debug Mode

If you are working with a debug mode you will need to rename this module "_trail.pyd" to "_trail_d.pyd"

Missing DLL

The .pyd file may require a dll or other dependency that is not available and cant be imported due to that. there are tools such as depends.exe or this that allow you to find what is required

Name Space Issue

If there was a file already called "_trail.py" in the python path that could create unwanted behavior.

1 Comment

Yes. How can I change my path so that this file is detected. Everything has been copied to APP folder so shouldn't it find this file automatically?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.