python/django-“无法使用 ImageField,因为 Pillow 未安装”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25662073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:27:10  来源:igfitidea点击:

python/django - "Cannot use ImageField because Pillow is not installed"

pythondjangopippillow

提问by lapin

I'm joining a project, so I want to set up the environnment, so what I did is :

我正在加入一个项目,所以我想设置环境,所以我所做的是:

pip install -r requirements.txt

This fully installed all requirements including django 1.7.0, Pillow 2.4.0 and some others.

这完全安装了所有要求,包括 django 1.7.0、Pillow 2.4.0 和其他一些要求。

Then I want to build the database :

然后我想建立数据库:

python manage.py migrate

And boom, error, I get the following :

繁荣,错误,我得到以下信息:

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".

... like I didn't install Pillow. So I checked the installed package (with thistechnique), and Pillow 2.4.0IS installed.

...就像我没有安装枕头一样。所以我检查了已安装的包(使用这种技术),并Pillow 2.4.0安装了 IS。

Then, I also tried to force reinstall : pip install --upgrade --force-reinstall Pillow==2.4.0

然后,我还尝试强制重新安装: pip install --upgrade --force-reinstall Pillow==2.4.0

But, nothing to do I get the same error when running migrate.

但是,无事可做我在运行时遇到相同的错误migrate

I'm using python 3.4.0and django 1.7.0on a mac OS X 10.6.7 wrapped in virtualenv 1.11.6with pip downgraded to pip 1.2.1(because of some well-known-yet-not-fully-resolved-nor-understood issuewith pip and ssl).

我使用python 3.4.0,并django 1.7.0在Mac OS X 10.6.7包裹在virtualenv 1.11.6与PIP降级pip 1.2.1(因为一些知名尚未未完全解决的,也不是理解的问题与PIP和SSL)。

All of the code above is within virtualenv (bin/activatedone).

上面的所有代码都在 virtualenv 中(bin/activate完成)。

Do you have any ideas on why this problem and how to resolve it?

您对为什么会出现此问题以及如何解决有任何想法吗?

- - - - - - EDIT - - - - - -

- - - - - - 编辑 - - - - - -

When I run the above force-reinstall command, (so many code gets outpouted I can't paste it all but) although it finishes with "Successfully installed Pillow", there's some warnings in the code :

当我运行上面的 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.

采纳答案by lapin

I tried :

我试过 :

  • Reinstall globaly PIL by compiling "Imaging-1.1.7" using some instructions here, but didn't work
  • Reinstall Pillow and it's dependency globally using that link, but didn't work
  • Reinstall GCC4.2 using this link, but it didn't work
  • 通过使用此处的一些说明编译“Imaging-1.1.7”来重新安装 globaly PIL ,但没有用
  • 使用该链接重新安装 Pillow 及其全局依赖项,但不起作用
  • 使用此链接重新安装 GCC4.2 ,但它不起作用

I finally figured out I was in the case described in the wonderfull answer to this post. In other words, I am running a mac whose CPU is capable of 64bit but whose kernel firmware is set to 32bit. Which is a problem as the project I'm working on was built for 64bit.

我终于发现我属于这篇文章的精彩答案中描述的情况。换句话说,我正在运行一台 mac,其 CPU 支持 64 位,但内核固件设置为 32 位。这是一个问题,因为我正在处理的项目是为 64 位构建的。

As explained in that post, when you install python3 using an installer (DMG) it will sniff if the kernel is set to 32 bit and install 32bit version of python 3 accordingly. But if you just download the tarball source from python's website and install it with :

该帖子所述,当您使用安装程序 (DMG) 安装 python3 时,它会检测内核是否设置为 32 位并相应地安装 32 位版本的 python 3。但是,如果您只是从 python 的网站下载 tarball 源代码并使用以下命令安装它:

cd Python-3.4.1
./configure
make
sudo make install

Then the 64bit version of python3 should be installed. Which you can verify by doing :

然后应该安装64位版本的python3。您可以通过执行以下操作来验证:

file /usr/local/bin/python3
/usr/local/bin/python3: Mach-O 64-bit executable x86_64

That done, all problems are gone with PIL/Pillow in the virtualenv using this 64bit version of python3. Even the pip downgrade became unnecessary.

完成后,使用此 64 位版本的 python3,在 virtualenv 中使用 PIL/Pillow 的所有问题都消失了。甚至 pip 降级也变得没有必要。

回答by The Wanderer

Had a similar problem, and my solution was much simpler:

有一个类似的问题,我的解决方案要简单得多:

Apparently packages PIL and Pillow can't coexist. If you want to use Pillow you first have to uninstall PIL and then install Pillow.

显然包 PIL 和 Pillow 不能共存。如果你想使用 Pillow 你首先必须卸载 PIL 然后安装 Pillow

If you are on Mac, you have to install a few libraries as well using brew. Mentioned below is the sequence of steps:

如果您使用的是 Mac,则还必须使用 brew 安装一些库。下面提到的是步骤顺序:

$pip uninstall PIL
$brew install libtiff libjpeg webp little-cms2
$pip install Pillow

To test if pillow is installed and ready to use, open python interpreter and try to import the following:

要测试枕头是否已安装并可以使用,请打开 python 解释器并尝试导入以下内容:

>>> from PIL import Image

*note that the library still says PIL but now it is importing from Pillow instead of PIL.

*请注意,图书馆仍然说 PIL,但现在它是从 Pillow 而不是 PIL 导入的。

If you are able to successfully import then you are good to go (in all probability you won't have to worry about setting PYTHONPATH or 32/64-bit installations)

如果您能够成功导入,那么您就可以开始了(很可能您不必担心设置 PYTHONPATH 或 32/64 位安装)

Source: https://pillow.readthedocs.io/en/latest/installation.html

来源:https: //pillow.readthedocs.io/en/latest/installation.html

回答by slashdottir

I had this error using PyCharm's debugger. I had to go to Settings->'Project Interpreter' highlight 'Pillow' and hit the little up arrow on the right to upgrade it. Then the error disappeared.

我在使用 PyCharm 的调试器时遇到了这个错误。我不得不去设置->“项目解释器”突出显示“枕头”并点击右侧的小向上箭头来升级它。然后错误消失了。

回答by MD Shahrouq

I was too getting same problem while implememnting Image Upload using CLoudinary , but found the Above answer, but in some other way.

我在使用 CLoudinary 实现图像上传时也遇到了同样的问题,但找到了上述答案,但以其他方式。

 sudo pip uninstall PIL

 sudo pip uninstall Pillow

 sudo pip install Pillow

After that mine Problem was solved !

之后我的问题就解决了!

回答by PatrickReagan

I was having this problem on a Mac with Python 3.6.4. The solution was to uninstall Pillow 5.1.0 and instead install 5.0.0.

我在使用 Python 3.6.4 的 Mac 上遇到了这个问题。解决方案是卸载 Pillow 5.1.0 并安装 5.0.0。

pip uninstall Pillow
pip install Pillow==5.0.0

回答by Arun Selvakumar Govindaraj

For python3 make sure your $PYTHONPATHhas the virtualenvpath and Instead of running the command

对于 python3 确保你$PYTHONPATHvirtualenv路径而不是运行命令

python manage.py migrate

Run:

跑:

python3 manage.py migrate

回答by Nick Patsiuk

macOS High Sierra 10.13.6 My solution was

macOS High Sierra 10.13.6 我的解决方案是

pip3 install Pillow

Not

不是

pip install Pillow

回答by Parth Karia

If you are using Pillow 4.1.0 with Python 3.6.0 then upgrading the Python version will fix this issue. Found the solution here: https://github.com/python-pillow/Pillow/issues/2479#issuecomment-292252147

如果您将 Pillow 4.1.0 与 Python 3.6.0 一起使用,则升级 Python 版本将解决此问题。在这里找到解决方案:https: //github.com/python-pillow/Pillow/issues/2479#issuecomment-292252147

回答by Taranis

I had the same problem in my virtual environment, even though Pillow was installed. Also installing a lower version didn't help. As soon I left my virtual environment it worked. Maybe this is helping someone.

即使安装了 Pillow,我在我的虚拟环境中也遇到了同样的问题。安装较低版本也无济于事。一旦我离开我的虚拟环境,它就起作用了。也许这是在帮助某人。

There is the command:

有命令:

    (wb_env) C:\Users\Taranis\Dropbox_Coding\Python 
    Coding\Programme\Projekt_Webblog\tim_webblog>python manage.py makemigrations app_webblog

The error:

错误:

    SystemCheckError: System check identified some issues:

    ERRORS:
    app_webblog.BlogEntry.entry_img: (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".

回答by Don Grem

What worked for me was to uninstall Pillow from user folder and install it with sudo.

对我有用的是从用户文件夹中卸载 Pillow 并使用sudo.

Initial install was:

初始安装是:

$ pip3 install Pillow --user

installed to: ~/.local/lib/python3.7/site-packages/Pillow-7.0.0.dist-info

安装到: ~/.local/lib/python3.7/site-packages/Pillow-7.0.0.dist-info

So first uninstalled it and then installed with sudo:

所以首先卸载它,然后安装sudo

$ pip3 uninstall Pillow
$ sudo pip3 install Pillow

new location: /usr/local/lib64/python3.7/site-packages/Pillow-7.0.0.dist-infoand problem was fixed.

新位置:/usr/local/lib64/python3.7/site-packages/Pillow-7.0.0.dist-info问题已解决。