我正在加入一个项目,所以我想建立环境,所以我做的是:
pip install -r requirements.txt
这完全安装了所有要求,包括django 1.7.0,Pillow 2.4.0和其他一些。
然后我想构建数据库:
python manage.py migrate
繁荣,错误,我得到以下:
CommandError: System check identified some issues:
ERRORS:
stu.chan.icon: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip install pillow".
stu.chan.image: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip install pillow".
stu.Piec.icon: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip install pillow".
...就像我没有安装枕头。所以我检查了已安装的软件包(使用this技术),并安装了Pillow 2.4.0
。
然后,我也试图强制重新安装:pip install --upgrade --force-reinstall Pillow==2.4.0
但是,无所事事我在运行migrate
时遇到同样的错误。
我在python 3.4.0
包裹的mac OS X 10.6.7上使用django 1.7.0
和virtualenv 1.11.6
,pip降级为pip 1.2.1
(因为一些众所周知但尚未完全解析也未理解的issue与pip和ssl)。
上面的所有代码都在virtualenv(bin/activate
完成)内。
您对此问题的原因以及解决方法有什么想法吗?
- - - - - - 编辑 - - - - - -
当我运行上面的force-reinstall命令时,(这么多代码都被打败了,我不能把它全部粘贴掉)尽管它以“成功安装的枕头”完成,但代码中有一些警告:
building 'PIL._imaging' extension
(blabla code)
_imaging.c:975:13: warning: array index of '1' indexes past the end of an array (that contains 1 elements) [-Warray-bounds]
value = PyTuple_GET_ITEM(xy, 1);
^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/python3.4m/tupleobject.h:58:34: note: instantiated from:
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
^
/usr/local/include/python3.4m/tupleobject.h:27:5: note: array 'ob_item' declared here
PyObject *ob_item[1];
^
1 warning generated.
(blabla code)
libImaging/Unpack.c:867:1: warning: unused function 'copy3' [-Wunused-function]
copy3(UINT8* out, const UINT8* in, int pixels)
^
1 warning generated.
我在使用Python 3.6.4的Mac上遇到了这个问题。解决方案是卸载Pillow 5.1.0,而不是安装5.0.0。
pip uninstall Pillow
pip install Pillow==5.0.0
我试过了 :
我终于想通了我在this post的精彩回答中描述的情况。换句话说,我正在运行一个mac,其CPU能够达到64位,但其内核固件设置为32位。这是一个问题,因为我正在研究的项目是为64位构建的。
正如在that post中所解释的,当你使用安装程序(DMG)安装python3时,如果内核设置为32位并且相应地安装32位版本的python 3,它将会嗅探。但是如果你只是从python的网站下载tarball源代码并安装它:
cd Python-3.4.1
./configure
make
sudo make install
然后应该安装64位版本的python3。您可以通过以下方式验证:
file /usr/local/bin/python3
/usr/local/bin/python3: Mach-O 64-bit executable x86_64
这样做,所有问题都在使用这个64位版本的python3的virtualenv中的PIL / Pillow消失了。即使点数降级也没必要了。
我使用PyCharm的调试器时遇到此错误。我不得不去设置 - >'Project Interpreter'突出显示'Pillow'并点击右侧的小向上箭头进行升级。然后错误消失了。
我在使用CLoudinary实现Image Upload时遇到了同样的问题,但是找到了上面的答案,但是还有其他一些方法。
sudo pip uninstall PIL
sudo pip uninstall Pillow
sudo pip install Pillow
之后我的问题解决了!
有类似的问题,我的解决方案更简单:
显然包PIL和Pillow不能共存。如果你想使用Pillow,你首先要卸载PIL,然后安装Pillow。
如果您使用的是Mac,则必须使用brew安装一些库。下面提到的是一系列步骤:
$pip uninstall PIL
$brew install libtiff libjpeg webp little-cms2
$pip install Pillow
要测试枕头是否已安装并准备使用,请打开python interpreter并尝试导入以下内容:
>>> from PIL import Image
*请注意,该库仍然显示PIL,但现在它是从Pillow而不是PIL导入的。
如果你能够成功导入那么你很高兴(很可能你不必担心设置PYTHONPATH或32/64位安装)
资料来源:https://pillow.readthedocs.io/en/latest/installation.html
对于python3,请确保您的$PYTHONPATH
具有virtualenv
路径而不是运行命令
python manage.py migrate
跑:
python3 manage.py migrate
macOS High Sierra 10.13.6我的解决方案是
pip3 install Pillow
不
pip install Pillow
如果您使用Pillow 4.1.0和Python 3.6.0,那么升级Python版本将解决此问题。在这里找到解决方案:https://github.com/python-pillow/Pillow/issues/2479#issuecomment-292252147