gpt4 book ai didi

docker - 在 Docker 中使用 Pillow

转载 作者:IT老高 更新时间:2023-10-28 21:22:55 25 4
gpt4 key购买 nike

由于某种原因,我无法在 docker 中安装 python 的 PIL 模块。这是我所拥有的描述:

requirements.txt

Pillow
flask
redis

Dockerfile

FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py

app.py

import PIL

命令

$ sudo docker build -t web .
Installing collected packages: Pillow, Werkzeug, MarkupSafe, Jinja2, itsdangerous, flask, redis
Successfully installed Jinja2-2.8 MarkupSafe-0.23 Pillow-2.9.0 Werkzeug-0.10.4 flask-0.10.1 itsdangerous-0.24 redis-2.10.3
---> 91dfb38bd480
Removing intermediate container 4e4ca5801814
Step 4 : CMD python app.py
---> Running in e71453f2fab6
---> d62996658bd6
Removing intermediate container e71453f2fab6
Successfully built d62996658bd6

$ sudo docker-compose up

这是我得到的:输出

web_1   |   File "app.py", line 1, in <module>
web_1 | import PIL
web_1 | ImportError: No module named PIL

我认为在 requirements.txt 中添加 PIL 可能会起作用,但这是我构建时会发生的情况

$ sudo docker build -t web .
....
Collecting PIL (from -r requirements.txt (line 1))
Could not find a version that satisfies the requirement PIL (from -r requirements.txt (line 1)) (from versions: )
Some externally hosted files were ignored as access to them may be unreliable (use --allow-external PIL to allow).
No matching distribution found for PIL (from -r requirements.txt (line 1))

知道应该从这里做什么吗?

最佳答案

在 Dockerfile 中添加 RUN apk add zlib-dev jpeg-dev gcc musl-dev 然后在 requirements.txt 中添加 Pillow

关于docker - 在 Docker 中使用 Pillow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32802682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com