Django - no module named PIL

I need to use ImageField in my models, and PIL doesn't seem to install:

 >>> from PIL import Image Traceback (most recent call last): File "<console>", line 1, in <module> ImportError: No module named PIL 

However, I see that a python image is installed in Synaptic. When I try to install it easily, 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 applicable. Do I need to do something to use the ImageField field type?

+6
source share
5 answers

Samuele Mattiuzzo gave me the answer:

Have you tried to import an image instead of importing a PIL image? sometimes it solves the problem

+6
source

Also sometimes this may not work:

 pip install pil 

Check this out: gcc error trying to install PIL in Python2.6 virtual directory

+1
source

If your question is: "Why is support for JPEG, FREETYPE2, etc. not available?",

PIL installs with support for packages that are already present on your system when installing PIL.

To support JPEG and FREETYPE, install the following packages:

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

If you just installed it on OS X Lion, and a third-party library cannot from PIL import image , you can just do ln -s PIL-OSX... PIL

0
source

I know this is an old question, but I found another way to solve it, which fixed the problems on my server. The PIL package was installed by easy_install and saved in "/usr/local/lib/python2.6/site-packages/PIL-1.1.7-py2.6-linux-x86_64.egg". Looking back at its contents, he:

 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. There is no PIL module to import from. So I did the dirty trick. Created a folder called PIL and copied all these files inside it.

 mkdir PIL cp * PIL/ 

So, everything began to work fine. I think this is a problem, depending on the installation package you are using, it will be deployed differently .;)

0
source

The problem is related to the configuration of package managers (.py) PIL:

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

Possible solutions:

  • Rename the EGG to "PIL".
  • Correct your code in the installed package (not always possible).
  • Hack like Jamie did (elsewhere on this page.)
  • Use another package to install.
  • Manually configure setup.py for your installation.

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

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

This may be surprising, but it actually works in many situations.

0
source

Source: https://habr.com/ru/post/892007/


All Articles