Django很难找到枕头,但我不确定为什么。
基于Linux Alpine的Docker映像,Django 2.2。以下是相关部分:
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
[[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)
在查看/usr/local/lib/python3.7/site-packages
时,我注意到我同时拥有 PIL 和 Pillow 。是这样:
基于以下事实:i)pip uninstall PIL
-> not installed
ii)print(PIL.PILLOW_VERSION)
-> 5.0.0
在python的外壳中,并且iii)Django使用from PIL import Image
{ {3}},我会假设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
,但是,以某种方式,这似乎还不够。还在挖。感谢您提供任何线索
答案 0 :(得分:1)
Turns out, jpeg-dev
(required by the compilation) was not enough to satisfy all dependencies during execution. Adding libjpeg
solved the issue. Updated Dockerfile
# install mysqlclient
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
RUN apk add libjpeg -------------> et voila
COPY ./Pipfile /usr/src/cms/Pipfile
RUN pipenv install --skip-lock --system --dev
RUN apk del build-deps