Reputation: 3
I've been trying this for awhile now with no luck. Making a basic api but running into some trouble with the flask_restful module. This is my code:
import markdown
import os
import shelve
from flask import Flask, g
from flask_restful import Resource, Api, reqparse
app = Flask(__name)
@app.route("/")
def index():
with open(os.path.dirname(app.root_path) +
'/README.md', 'r') as markdown_file:
content = markdown_file.read()
return markdown.markdown(content)
This is my requirements.txt:
docker==3.4.1
docker-compose==1.22.0
docker-pycreds==0.3.0
dockerpty==0.4.1
docopt==0.6.2
Flask==1.0.2
Flask-RESTful==0.3.6
requests==2.18.4
urllib3==1.22
websocket-client==0.48.0
This is what I get as an error when running docker-compose up:
Starting python-rest_device-registry_1 ... done
Attaching to python-rest_device-registry_1
device-registry_1 | Traceback (most recent call last):
device-registry_1 | File "./run.py", line 1, in <module>
device-registry_1 | from device_registry import app
device-registry_1 | File "/usr/src/app/device_registry/__init__.py", line 6,
in <module>
device-registry_1 | from flask_restful import Resource, Api, reqparse
device-registry_1 | ModuleNotFoundError: No module named 'flask_restful'
python-rest_device-registry_1 exited with code 1
My docker file is this:
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./run.py" ]
What am I doing wrong here? I pip installed Flask and flask_restful but I'm lost for word on what's going on.
Upvotes: 0
Views: 3882
Reputation: 309
It does not look like you are using flask_restful
in the code you are showing here. You are just importing it. It might be possible that you started out with just some flask code, which imports ok, then added flask-restful to your requirements file but docker in unaware of it and it has a cached version of that part of the container.
Try to decouple your problem, start by running your python sample outside docker, in a plain old virtualenv and make sure that starts. Then mess look into how docker is installing or not your newly added requirements.
Upvotes: 1