python / django - “不能使用ImageField,因為沒有安裝Pillow”

[英]python/django - “Cannot use ImageField because Pillow is not installed”


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 this technique), and Pillow 2.4.0 IS 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.

但是,無所事事我在運行遷移時遇到了同樣的錯誤。

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

我在macOS X 10.6.7上使用python 3.4.0和django 1.7.0包裝在virtualenv 1.11.6中,pip降級為pip 1.2.1(因為一些眾所周知但尚未完全解析 - 與pip和ssl有關的問題。

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

上面的所有代碼都在virtualenv(bin / activate done)中。

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.

6 个解决方案

#1


15  

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

#2


5  

I tried :

我試過了 :

  • Reinstall globaly PIL by compiling "Imaging-1.1.7" using some instructions here, but didn't work
  • 通過使用這里的一些說明編譯“Imaging-1.1.7”重新安裝globaly PIL,但是沒有用
  • Reinstall Pillow and it's dependency globally using that link, but didn't work
  • 使用該鏈接全局重新安裝Pillow及其依賴關系,但不起作用
  • Reinstall GCC4.2 using this link, but it didn't work
  • 使用此鏈接重新安裝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消失了。即使點數降級也沒必要了。

#3


1  

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的調試器時遇到了這個錯誤。我不得不去設置 - >'Project Interpreter'突出顯示'Pillow'並點擊右側的小向上箭頭進行升級。然后錯誤消失了。

#4


1  

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

我在使用CLoudinary實現Image Upload時遇到了同樣的問題,但是找到了上面的答案,但是在其他方面。

 sudo pip uninstall PIL

 sudo pip uninstall Pillow

 sudo pip install Pillow

After that mine Problem was solved !

之后我的問題解決了!

#5


1  

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

#6


0  

For python3 make sure your $PYTHONPATH have the virtualenv path and Instead of running the command python manage.py migrate Give, python3 manage.py migrate

對於python3,請確保您的$ PYTHONPATH具有virtualenv路徑而不是運行命令python manage.py migrate Give,python3 manage.py migrate


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/09/04/7257edeb43b1ccce5276abe545ade2db.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com