我需要在我的模型中使用ImageField
,而 PIL 似乎没有安装:
>>> from PIL import Image
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named PIL
但是我可以在 Synaptic 中看到 python-imaging 。当我尝试轻松安装它时,我得到:
$ 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
字段类型?
答案 0 :(得分:6)
您是否尝试使用导入图像而不是PIL导入图像?有时这解决了问题
答案 1 :(得分:1)
答案 2 :(得分:0)
如果你的问题是“为什么支持JPEG,FREETYPE2等,不可用?”,
安装PIL时,PIL会安装支持您系统中已存在的软件包。
支持JPEG和FREETYPE安装以下软件包:
sudo aptitude install libjpeg libjpeg-dev
sudo aptitude install libfreetype6 libfreetype6-dev
如果您刚刚在OS X Lion上安装了它而第三方lib无法from PIL import image
,那么您只需执行ln -s PIL-OSX... PIL
答案 3 :(得分:0)
我知道这是一个已经回答的旧问题,但我找到了另一种方法来解决它,纠正了我服务器中的问题。 PIL包由easy_install安装并存储在“/usr/local/lib/python2.6/site-packages/PIL-1.1.7-py2.6-linux-x86_64.egg”中。查看其内容导致:
ArgImagePlugin.py FpxImagePlugin.py ImageColor.pyc ImagePalette.py _imagingmath.so PaletteFile.pyc SunImagePlugin.py
ArgImagePlugin.pyc FpxImagePlugin.pyc ImageDraw2.py ImagePalette.pyc _imaging.py PalmImagePlugin.py SunImagePlugin.pyc
BdfFontFile.py GbrImagePlugin.py ImageDraw2.pyc ImagePath.py _imaging.pyc PalmImagePlugin.pyc TarIO.py
BdfFontFile.pyc GbrImagePlugin.pyc ImageDraw.py ImagePath.pyc _imaging.so PcdImagePlugin.py TarIO.pyc
BmpImagePlugin.py GdImageFile.py ImageDraw.pyc Image.py ImImagePlugin.py PcdImagePlugin.pyc TgaImagePlugin.py
BmpImagePlugin.pyc GdImageFile.pyc ImageEnhance.py Image.pyc ImImagePlugin.pyc PcfFontFile.py TgaImagePlugin.pyc
BufrStubImagePlugin.py GifImagePlugin.py ImageEnhance.pyc ImageQt.py ImtImagePlugin.py PcfFontFile.pyc TiffImagePlugin.py
BufrStubImagePlugin.pyc GifImagePlugin.pyc ImageFileIO.py ImageQt.pyc ImtImagePlugin.pyc PcxImagePlugin.py TiffImagePlugin.pyc
ContainerIO.py GimpGradientFile.py ImageFileIO.pyc ImageSequence.py __init__.py PcxImagePlugin.pyc TiffTags.py
ContainerIO.pyc GimpGradientFile.pyc ImageFile.py ImageSequence.pyc __init__.pyc PdfImagePlugin.py TiffTags.pyc
CurImagePlugin.py GimpPaletteFile.py ImageFile.pyc ImageShow.py IptcImagePlugin.py PdfImagePlugin.pyc WalImageFile.py
CurImagePlugin.pyc GimpPaletteFile.pyc ImageFilter.py ImageShow.pyc IptcImagePlugin.pyc PixarImagePlugin.py WalImageFile.pyc
DcxImagePlugin.py GribStubImagePlugin.py ImageFilter.pyc ImageStat.py JpegImagePlugin.py PixarImagePlugin.pyc WmfImagePlugin.py
DcxImagePlugin.pyc GribStubImagePlugin.pyc ImageFont.py ImageStat.pyc JpegImagePlugin.pyc PngImagePlugin.py WmfImagePlugin.pyc
EGG-INFO Hdf5StubImagePlugin.py ImageFont.pyc ImageTk.py McIdasImagePlugin.py PngImagePlugin.pyc XbmImagePlugin.py
EpsImagePlugin.py Hdf5StubImagePlugin.pyc ImageGL.py ImageTk.pyc McIdasImagePlugin.pyc PpmImagePlugin.py XbmImagePlugin.pyc
EpsImagePlugin.pyc IcnsImagePlugin.py ImageGL.pyc ImageTransform.py MicImagePlugin.py PpmImagePlugin.pyc XpmImagePlugin.py
ExifTags.py IcnsImagePlugin.pyc ImageGrab.py ImageTransform.pyc MicImagePlugin.pyc PsdImagePlugin.py XpmImagePlugin.pyc
ExifTags.pyc IcoImagePlugin.py ImageGrab.pyc ImageWin.py MpegImagePlugin.py PsdImagePlugin.pyc XVThumbImagePlugin.py
FitsStubImagePlugin.py IcoImagePlugin.pyc ImageMath.py ImageWin.pyc MpegImagePlugin.pyc PSDraw.py XVThumbImagePlugin.pyc
FitsStubImagePlugin.pyc ImageChops.py ImageMath.pyc _imagingft.py MspImagePlugin.py PSDraw.pyc
FliImagePlugin.py ImageChops.pyc ImageMode.py _imagingft.pyc MspImagePlugin.pyc SgiImagePlugin.py
FliImagePlugin.pyc ImageCms.py ImageMode.pyc _imagingft.so OleFileIO.py SgiImagePlugin.pyc
FontFile.py ImageCms.pyc ImageOps.py _imagingmath.py OleFileIO.pyc SpiderImagePlugin.py
FontFile.pyc ImageColor.py ImageOps.pyc _imagingmath.pyc PaletteFile.py SpiderImagePlugin.pyc
好。没有要从中导入的模块PIL。所以,我做了一个肮脏的把戏。制作了一个名为PIL的文件夹,并将所有这些文件复制到其中。
mkdir PIL
cp * PIL/
所以,一切都开始好起来了。我认为这是问题所在,取决于您使用的安装包,它将以不同的方式部署。 ;)
答案 4 :(得分:0)
问题来自包管理器如何设置(.py)PIL:
https://mail.python.org/pipermail/image-sig/2010-August/006480.html
可能的解决方案:
“重命名EGG”在本页的其他地方没有描述,所以我将在这里描述:
cd /usr/local/lib/python2.6/site-packages/
mv PIL-1.1.7-py2.6-linux-i686.egg PIL
这可能会令人惊讶,但这实际上适用于许多情况。