Django - 没有名为 PIL 的模块

发布于 2024-11-18 06:34:58 字数 2549 浏览 2 评论 0原文

我需要在我的模型中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

他是夢罘是命 2024-11-25 06:34:58

Samuele Mattiuzzo 给了我答案:

您是否尝试过使用 import Image 而不是 from PIL import Image ?有时这可以解决问题

Samuele Mattiuzzo gave me the answer:

have you tried with import Image instead of from PIL import Image? sometimes this solves the issue

夜未央樱花落 2024-11-25 06:34:58

有时这可能不起作用:

pip install pil 

检查一下:gcc error attempts to install PIL in a Python2.6 virtualenv

Also sometimes this may not work:

pip install pil 

Check this out : gcc error trying to install PIL in a Python2.6 virtualenv

∝单色的世界 2024-11-25 06:34:58

我知道这是一个已经回答的老问题,但我找到了另一种方法来解决它,纠正了我的服务器中的问题。
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/

所以,一切开始顺利。我认为这就是问题所在,根据你使用的安装包,它会以不同的方式部署。 ;)

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:

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

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.

mkdir PIL
cp * PIL/

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. ;)

日久见人心 2024-11-25 06:34:58

如果您的问题是“为什么对 JPEG、FREETYPE2 等的支持不可用?”,

PIL 将在您安装 PIL 时安装对系统中已存在的软件包的支持。

要支持 JPEG 和 FREETYPE,请安装以下软件包:

sudo aptitude install libjpeg libjpeg-dev
sudo aptitude install libfreetype6 libfreetype6-dev

如果您刚刚在 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:

sudo aptitude install libjpeg libjpeg-dev
sudo aptitude install libfreetype6 libfreetype6-dev

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 a ln -s PIL-OSX... PIL

农村范ル 2024-11-25 06:34:58

问题来自包管理器如何设置(.py)PIL:

https ://mail.python.org/pipermail/image-sig/2010-August/006480.html

可能的解决方案:

  • 将 EGG 重命名为“PIL”。
  • 将您的代码调整为已安装的软件包(并不总是可行。)
  • 像 Jayme 那样执行 hack(本页其他位置)。
  • 使用不同的软件包进行安装。
  • 为您的安装手动配置 setup.py。

“重命名 EGG”在本页其他地方没有描述,所以我将在这里描述它:

cd /usr/local/lib/python2.6/site-packages/
mv PIL-1.1.7-py2.6-linux-i686.egg PIL

这可能会令人惊讶,但这实际上在很多情况下都有效。

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 to "PIL."
  • Adjust your code to your installed package (not always possible.)
  • Perform a hack like Jayme did (elsewhere on this page.)
  • Use a different package for installation.
  • Manually configure setup.py for your installation.

"Rename the EGG" is not described elsewhere on this page, so I'll describe it here:

cd /usr/local/lib/python2.6/site-packages/
mv PIL-1.1.7-py2.6-linux-i686.egg PIL

It may be surprising, but this actually works in many situations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文