【发布时间】:2019-10-17 19:40:09
【问题描述】:
Django 很难找到 Pillow,我不太清楚为什么。
环境
基于 Linux Alpine 的 Docker 映像,Django 2.2。以下是相关部分:
Dockerfile
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev jpeg-dev zlib-dev \
&& apk add --no-cache mariadb-dev mariadb-client
# install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
RUN pip install mysqlclient
COPY ./Pipfile /usr/src/cms/Pipfile
RUN pipenv install --skip-lock --system --dev
RUN apk del build-deps
Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
django = "==2.2"
markdown = "==3.1.1"
pillow = "==5.0.0"
[requires]
python_version = "3.6"
问题
当我从容器运行 python manage.py runserver 0.0.0.0:8000 时,我收到以下错误:
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
website.Photo.photo: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "pip install Pillow".
这奇怪因为pip install Pillow给了我
Requirement already satisfied: Pillow in /usr/local/lib/python3.7/site-packages (5.4.1)
关于Pillow与PIL的冲突
查看/usr/local/lib/python3.7/site-packages 时,我注意到我同时拥有PIL 和Pillow。这是:
- 冲突的来源 (Pillow's documentation) 非常具体地说明需要卸载 PIL
- pillow 使用 PIL 这个名字来保持兼容性,正如this discussion? 中所建议的那样
根据 i) pip uninstall PIL -> not installed ii) print(PIL.PILLOW_VERSION) -> 5.0.0 在 python 的外壳中以及 iii) Django 使用 from PIL import Image source 的事实,我会选择假设 2。那么如果容器中安装了 Pillow,为什么 Django 找不到呢?
当前路径
>>> from PIL import Image
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 58, in <module>
from . import _imaging as core
ImportError: Error loading shared library libjpeg.so.8: No such file or directory (needed by /usr/local/lib/python3.7/site-packages/PIL/_imaging.cpython-37m-x86_64-linux-gnu.so)
我在 Dockerfile 中添加了jpeg-dev,但不知何故,这似乎还不够。还在挖。感谢您提供任何线索
【问题讨论】:
-
有什么理由将 Pillow 5.0.0 与 Python 3.7 一起使用?
-
根据我的阅读,Django 不支持 5.0.0 以上的 Pillow,我使用 Python 3.7 开始了我的项目。哦,刚刚看到
Python 3.7->Pillow>5.2 -
我刚刚回滚到
python 3.6,同样的问题。我编辑帖子
标签: python django docker python-imaging-library alpine