Using -6ren">
gpt4 book ai didi

python - Gunicorn导入错误: No module named app

转载 作者:太空宇宙 更新时间:2023-11-03 20:16:55 30 4
gpt4 key购买 nike

我写了一个 dockerfile 并且正在运行 docker build -t test .但我在最后一行收到此错误。

Step 15/16 : WORKDIR "/API"
---> Using cache
---> c09969ab4023
Step 16/16 : RUN gunicorn -b localhost:5000 app
---> Running in 69c1859e7ba5
[2019-10-15 11:34:17 +0000] [7] [INFO] Starting gunicorn 19.9.0
[2019-10-15 11:34:17 +0000] [7] [INFO] Listening at: http://127.0.0.1:5000 (7)
[2019-10-15 11:34:17 +0000] [7] [INFO] Using worker: sync
[2019-10-15 11:34:17 +0000] [11] [INFO] Booting worker with pid: 11
[2019-10-15 11:34:17 +0000] [11] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
ImportError: No module named app
[2019-10-15 11:34:17 +0000] [11] [INFO] Worker exiting (pid: 11)
[2019-10-15 11:34:17 +0000] [7] [INFO] Shutting down: Master
[2019-10-15 11:34:17 +0000] [7] [INFO] Reason: Worker failed to boot.
The command '/bin/sh -c gunicorn -b localhost:5000 app' returned a non-zero code: 3

我怎么知道我做错了什么,因为我无法调试这个,而且我没有使用 docker 的经验,实际上只是一个初学者。我怀疑我所在的目录可能是错误的,或者不是?虽然我确信cd API/是正确的,我应该在的地方。

我的 Dockerfile 用于具有依赖项(例如 Caffe)的 Python 项目:

FROM ubuntu:18.04
RUN apt-get update -y && apt-get install -y python-pip python-virtualenv tesseract-ocr poppler-utils

#Install dependencies:
COPY requirements.txt .
RUN pip install -r requirements.txt

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
wget \
libatlas-base-dev \
libboost-all-dev \
libgflags-dev \
libgoogle-glog-dev \
libhdf5-serial-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libprotobuf-dev \
libsnappy-dev \
protobuf-compiler \
python-dev \
python-numpy \
python-pip \
python-setuptools \
python-scipy && \
rm -rf /var/lib/apt/lists/*

ENV CAFFE_ROOT=/opt/caffe
WORKDIR $CAFFE_ROOT

# FIXME: use ARG instead of ENV once DockerHub supports this
# https://github.com/docker/hub-feedback/issues/460
ENV CLONE_TAG=1.0

RUN git clone -b ${CLONE_TAG} --depth 1 https://github.com/BVLC/caffe.git . && \
# pip install --upgrade pip && \
cd python && for req in $(cat requirements.txt) pydot; do pip install $req; done && cd .. && \
mkdir build && cd build && \
cmake -DCPU_ONLY=1 .. && \
make -j"$(nproc)"

ENV PYCAFFE_ROOT $CAFFE_ROOT/python
ENV PYTHONPATH $PYCAFFE_ROOT:$PYTHONPATH
ENV PATH $CAFFE_ROOT/build/tools:$PYCAFFE_ROOT:$PATH
RUN echo "$CAFFE_ROOT/build/lib" >> /etc/ld.so.conf.d/caffe.conf && ldconfig

#WORKDIR /workspace

#Run
WORKDIR "/API"
RUN gunicorn -b localhost:5000 app

最佳答案

通过在 #Run 之前添加 COPY API/API 已修复此问题WORKDIR“/API”

关于python - Gunicorn导入错误: No module named app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58393929/

30 4 0