Django - 没有名为 PIL 的模块
我需要在我的模型中使用 ImageField
并且 PIL 似乎没有安装:
>>> from PIL import Image
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named PIL
但是我可以看到 python-imaging 安装在 Synaptic 中。当我尝试轻松安装它时,我得到:
$ sudo easy_install-2.7 PIL
[sudo] password for glide:
Searching for PIL
Reading http://pypi.python.org/simple/PIL/
Reading http://www.pythonware.com/products/pil
Reading http://effbot.org/zone/pil-changes-115.htm
Reading http://effbot.org/downloads/#Imaging
Best match: PIL 1.1.7
Downloading http://effbot.org/media/downloads/PIL-1.1.7.tar.gz
Processing PIL-1.1.7.tar.gz
Running PIL-1.1.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-HvRSQr/PIL-1.1.7/egg-dist-tmp-nDJHmU
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
libImaging/Quant.c: In function ‘rehash_collide’:
libImaging/Quant.c:154: warning: cast to pointer from integer of different size
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.1 (r271:86832, May 2 2011, 14:22:06)
[GCC 4.4.3]
--------------------------------------------------------------------
*** TKINTER support not available
*** JPEG support not available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
To check the build, run the selftest.py script.
zip_safe flag not set; analyzing archive contents...
Image: module references __file__
Adding PIL 1.1.7 to easy-install.pth file
Installing pilconvert.py script to /usr/local/bin
Installing pilprint.py script to /usr/local/bin
Installing pildriver.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installed /usr/local/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg
Processing dependencies for PIL
Finished processing dependencies for PIL
而且这仍然无法使用。我是否需要执行其他操作才能使用 ImageField
字段类型?
I need to use ImageField
in my models and PIL seems not to be installed:
>>> from PIL import Image
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named PIL
However I can see python-imaging installed in Synaptic. When I try to easy-install it, I get:
$ sudo easy_install-2.7 PIL
[sudo] password for glide:
Searching for PIL
Reading http://pypi.python.org/simple/PIL/
Reading http://www.pythonware.com/products/pil
Reading http://effbot.org/zone/pil-changes-115.htm
Reading http://effbot.org/downloads/#Imaging
Best match: PIL 1.1.7
Downloading http://effbot.org/media/downloads/PIL-1.1.7.tar.gz
Processing PIL-1.1.7.tar.gz
Running PIL-1.1.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-HvRSQr/PIL-1.1.7/egg-dist-tmp-nDJHmU
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
libImaging/Quant.c: In function ‘rehash_collide’:
libImaging/Quant.c:154: warning: cast to pointer from integer of different size
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.1 (r271:86832, May 2 2011, 14:22:06)
[GCC 4.4.3]
--------------------------------------------------------------------
*** TKINTER support not available
*** JPEG support not available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
To check the build, run the selftest.py script.
zip_safe flag not set; analyzing archive contents...
Image: module references __file__
Adding PIL 1.1.7 to easy-install.pth file
Installing pilconvert.py script to /usr/local/bin
Installing pilprint.py script to /usr/local/bin
Installing pildriver.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installed /usr/local/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg
Processing dependencies for PIL
Finished processing dependencies for PIL
And this is still not usable. Do I have to do something else to be able to use the ImageField
field type ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Samuele Mattiuzzo 给了我答案:
Samuele Mattiuzzo gave me the answer:
有时这可能不起作用:
检查一下:gcc error attempts to install PIL in a Python2.6 virtualenv
Also sometimes this may not work:
Check this out : gcc error trying to install PIL in a Python2.6 virtualenv
我知道这是一个已经回答的老问题,但我找到了另一种方法来解决它,纠正了我的服务器中的问题。
PIL包由easy_install安装并存储在“/usr/local/lib/python2.6/site-packages/PIL-1.1.7-py2.6-linux-x86_64.egg”中。查看其内容的结果是:
嗯。没有可以导入的模块 PIL。于是,我做了一个肮脏的把戏。创建一个名为 PIL 的文件夹并将所有这些文件复制到其中。
所以,一切开始顺利。我认为这就是问题所在,根据你使用的安装包,它会以不同的方式部署。 ;)
I know this is an old question already answered, but I found another way to solve it that corrected the problems in my server.
The PIL package was installed by easy_install and stored in "/usr/local/lib/python2.6/site-packages/PIL-1.1.7-py2.6-linux-x86_64.egg". Looking on its contents resulted on:
Well. No module PIL to import from. So, I did a dirty trick. Made a folder called PIL and copied all this files inside it.
So, everything started to work fine. I think this is the problem, depending on the instalation package you use, it will be deployed in a different way. ;)
如果您的问题是“为什么对 JPEG、FREETYPE2 等的支持不可用?”,
PIL 将在您安装 PIL 时安装对系统中已存在的软件包的支持。
要支持 JPEG 和 FREETYPE,请安装以下软件包:
如果您刚刚在 OS X Lion 上安装了它,并且第三方库无法
from PIL import image
,那么您只需执行ln -s PIL-OSX...PIL
If your question is "why is the support for JPEG, FREETYPE2 etc, not available?",
PIL installs with the support for the packages that are already present in your system while you install PIL.
For support of JPEG and FREETYPE install following packages:
If you have just installed it on OS X Lion and a third party lib cannot
from PIL import image
, then you can just do aln -s PIL-OSX... PIL
问题来自包管理器如何设置(.py)PIL:
https ://mail.python.org/pipermail/image-sig/2010-August/006480.html
可能的解决方案:
“重命名 EGG”在本页其他地方没有描述,所以我将在这里描述它:
这可能会令人惊讶,但这实际上在很多情况下都有效。
The problem comes from how package managers setup(.py) PIL:
https://mail.python.org/pipermail/image-sig/2010-August/006480.html
Possible solutions:
"Rename the EGG" is not described elsewhere on this page, so I'll describe it here:
It may be surprising, but this actually works in many situations.