Python项目在Docker内部找不到模块

Ale*_*uun 5 python docker

我正在尝试使用以下 Dockerfile 在 docker 内运行 python 项目以进行机器学习:

FROM python:3

RUN apt-get update \
    && apt-get install -yq --no-install-recommends \
    python3 \
    python3-pip
RUN pip3 install --upgrade pip==9.0.3 \
    && pip3 install setuptools

# for flask web server
EXPOSE 8081

# set working directory
ADD . /app
WORKDIR /app

# install required libraries
COPY requirements.txt ./
RUN pip3 install -r requirements.txt

# This is the runtime command for the container
CMD python3 app.py
Run Code Online (Sandbox Code Playgroud)

这是我的要求文件:

flask
scikit-learn[alldeps]
pandas
textblob
numpy
matplotlib[alldeps]
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试导入 textblob 和 pandas 时,我的 docker cmd 中出现了名为“X”的 no module 错误。 在此输入图像描述

|    warnings.warn(msg, category=FutureWarning)
| Traceback (most recent call last):
|    File "app/app.py", line 12, in <module>
|      from textblob import Textblob
| ImportError: No module named 'textblob'
exited with code 1
Run Code Online (Sandbox Code Playgroud)

文件夹结构

machinelearning:
    backend:
        app.py
        Dockerfile
        requirements.txt
    frontend:
        ... (frontend works fine.)
    docker-compose.yml
Run Code Online (Sandbox Code Playgroud)

有谁知道这个问题的解决方案?(我对 Docker 还很陌生,所以我可能错过了一些重要的东西。)

Lam*_*mbo 1

这对我有用

FROM python:3

RUN apt-get update
RUN apt-get install -y --no-install-recommends

# for flask web server
EXPOSE 8081

# set working directory
WORKDIR /app

# install required libraries
COPY requirements.txt .
RUN pip install -r requirements.txt

# copy source code into working directory
COPY . /app

# This is the runtime command for the container
CMD python3 app.py
Run Code Online (Sandbox Code Playgroud)