skip to Main Content

I have an error when I use docker, when I build my image, my Mongodb database launches but my python server does not launch and I get the following error:

2023-03-21 14:11:25 Traceback (most recent call last):
2023-03-21 14:11:25   File "/app/ServeurWeb.py", line 5, in <module>
2023-03-21 14:11:25     from flask_restful import Api, Resource, reqparse
2023-03-21 14:11:25 ModuleNotFoundError: No module named 'flask_restful'

However flask_restful is installed on my computer with the command

pip install flask_restful

2

Answers


  1. pip install flask_restful needs to be ran inside of your Dockerfile. Your host does not share packages with the image.

    Ideally, you use a requirements.txt file, instead, however.

    Login or Signup to reply.
  2. create a requirements.txt file in the same directory as Dockerfile.
    add flask_restful in the requirements.txt file.

    Then add the below code in your dockerfile.

    COPY requirements.txt .
    RUN pip install -r requirements.txt 
    

    Note that if you install flask_restful in your host system, your docker container won’t recognize that as docker container runs on a isolated environment.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search