我在Flask应用程序中使用了第三方软件包。当我在Flask应用程序和docker之外测试这些软件包时,它们工作正常。当我将它们包含在应用程序中时,在构建并运行docker之后,它在某些导入上会失败。我不知道应该怎么做才能使其正确导入模块。
这是项目的结构:
flask_app
├── Dockerfile
├── canetis
| ├── install.sh
| ├── __init__.py
| ├── align.py
| ├── utils.py
| ├── gentle
| ├── install.sh
| ├── gentle
| ├── __init__.py
| ├── resources.py
| ├── util
| ├── __init__.py
| ├── paths.py
| ├── ext
| ├── kaldi
| ├── install.sh
gentle
软件包是从canetis/install.sh
脚本中的git复制而来的。
使用的dockerfile:
FROM python:2.7
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
WORKDIR /app
RUN apt-get update
RUN pip install --upgrade pip
RUN apt-get update && \
apt-get -y install sudo
ADD ./requirements.txt ./requirements.txt
RUN pip install -r requirements.txt
ADD . /app
RUN cd ./canetis && ./install.sh && source ~/.bashrc
ENV WEB_CONCURRENCY 5
CMD gunicorn app:app
构建docker时,如果失败并出现以下错误:
| Traceback (most recent call last):
| File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
| "__main__", fname, loader, pkg_name)
| File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
| exec code in run_globals
| File "/app/app.py", line 3, in <module>
| import tasks
| File "tasks.py", line 3, in <module>
| from canetis.align import align
| File "canetis/align.py", line 3, in <module>
| from utils import run_gentle
| File "canetis/utils.py", line 2, in <module>
| import gentle as gentle
| File "/usr/local/lib/python2.7/site-packages/gentle/__init__.py", line 2, in <module>
| from resources import Resources
| File "/usr/local/lib/python2.7/site-packages/gentle/resources.py", line 4, in <module>
| from util.paths import get_resource, ENV_VAR
| ImportError: No module named util.paths
问题可能出在温和模块中有一个名为温和的子文件夹,因此python无法正确找到它吗?但是,为什么它在docker之外无法工作?任何帮助表示赞赏。