ModuleNotFoundError: No module named 'flask_restful'
ModuleNotFoundError: No module named 'flask_restful'
我已经尝试了一段时间,但没有成功。使用 flask_restful 模块使基本 api 但 运行 遇到一些麻烦。这是我的代码:
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)
这是我的 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
这是我在 运行 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
我的 docker 文件是这样的:
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./run.py" ]
我在这里做错了什么?我 pip 安装了 Flask 和 flask_restful 但我不知道发生了什么事。
您在此处显示的代码中似乎没有使用 flask_restful
。你只是在导入它。您可能只是从一些 flask 代码开始,它导入 ok,然后将 flask-restful 添加到您的需求文件中,但 docker 没有意识到它并且它具有该部分的缓存版本容器。
尝试解耦你的问题,从 运行 你的 python 示例开始 docker,在一个普通的旧 virtualenv 中,并确保启动。然后再看看 docker 是如何安装或没有安装你新添加的要求的。
我已经尝试了一段时间,但没有成功。使用 flask_restful 模块使基本 api 但 运行 遇到一些麻烦。这是我的代码:
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)
这是我的 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
这是我在 运行 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
我的 docker 文件是这样的:
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./run.py" ]
我在这里做错了什么?我 pip 安装了 Flask 和 flask_restful 但我不知道发生了什么事。
您在此处显示的代码中似乎没有使用 flask_restful
。你只是在导入它。您可能只是从一些 flask 代码开始,它导入 ok,然后将 flask-restful 添加到您的需求文件中,但 docker 没有意识到它并且它具有该部分的缓存版本容器。
尝试解耦你的问题,从 运行 你的 python 示例开始 docker,在一个普通的旧 virtualenv 中,并确保启动。然后再看看 docker 是如何安装或没有安装你新添加的要求的。