Problems with Snow Leopard, Django & PIL - python

I am having some trouble getting Django & PIL work properly since upgrading to Snow Leopard.
I have installed freetype, libjpeg and then PIL, which tells me:
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
but when I try to upload a jpeg through the django admin interface I get:
Upload a valid image. The file you
uploaded was either not an image or a
corrupted image.
It works fine with PNG files.
Any Ideas?

Cato
I had the same experience with Leopard 10.5.x
Here is what I did to fix it, (may not work for you).
Go to your PIL working folder (where you unzipped PIL)
cd to your build folder
cd to your lib.macosx-10.* folder (specific to your os)
remove *.so
cd back to your PIL build folder
(I logged in as su for this, but you can sudo these if you like)
python setup.py clean
python setup.py build
python setup.py install
This rebuilds PIL clean. The reason your jpeg reports ok, is that it just looks for the existence of the jpeg lib files, but not the dependency that happens from a clean build and install of PIL.
Hope this solves your problem, mine was more likely related to the order of installation but maybe it will help...
Ken

As a follow up to Ken's response, I had the same problem with Snow Leopard 10.6.x which was caused by installing PIL before libjpeg. After installing libjpeg, I reinstalled PIL by doing the following.
cd to PIL working folder
python setup.py clean
python setup.py build_ext -i <-- This rebuilds PIL
python selftest.py - Run the selftest to confirm PIL is installed ok
python setup.py install

I ran into a similar issue while on Ubuntu 8.04. I was able to get myself out of it by simply re-issuing my PIL install (via pip):
pip install PIL --upgrade
Not sure what the issue was but I suspect it's similar to what others here reported.

Related

How can I fix my problems with PIL and Pillow in Visual Studio?

I'm using Visual Studio (not VS code) to write Python code. From Solution Explorer and then Python Environments I installed these packages: Pillow, Pillow-PIL, Pil-Lite, PillowImage. I also installed pip the same way. The problem is that when I write this code:
from PIL import Image:
myImage = Image.open("your_image_here");
myImage.show();
I get the message that PIL is unresolved, although that I have all of these packages.
I typed PIL in the solution explorer and there was a field: Run command: pip install PIL. I tried to install it, but I don't get it as a package. After that I uninstalled all other packages and tried to install this one again- the same thing.
I'm trying to run this elementary code since 3 days and there are no results. I tried installing it with CMD, but I'm only getting errors that pip is not recognized, although I used many different paths.
I will be very grateful, if you could help me about this issue.

While upgrading python imaging library (PIL), it tells me "JPEG support not available"

Using ubuntu 13.10, python 2.7.5:
>>> import _imaging, Image
>>> from PIL import Image, ImageDraw, ImageFilter, ImageFont
>>> im = Image.new('RGB', (300,300), 'white')
>>> draw = ImageDraw.Draw(im)
>>> font = ImageFont.truetype('arial.ttf', 14)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype
return FreeTypeFont(filename, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in __init__
self.font = core.getfont(file, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 34, in __getattr__
raise ImportError("The _imagingft C module is not installed")
**ImportError: The _imagingft C module is not installed**
>>>
So why does this happen? And how can I fix it? I followed the following instructions which I found at the bottom of this thread:
pip uninstall PIL
apt-get install libjpeg-dev
apt-get install libfreetype6-dev
apt-get install zlib1g-dev
apt-get install libpng12-dev
pip install PIL --upgrade
But while upgrading PIL, look what I saw:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1]
--------------------------------------------------------------------
*** TKINTER support not available
*** JPEG support not available
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
Is it normal for support for all these items not to be available? how do I fix that?
PIL is essentially dead, the fork Pillow is really what you should be using. You need to import it via
from PIL import Image, ...
It maintains all of the functionality of PIL, and adds a lot more, including Python 3 compatibility. Additionally, it's under active development, unlike PIL, so any bugs you find actually have a chance of getting fixed - same with feature requests.
You can install it (after uninstalling PIL) by running
pip install Pillow
I believe there's a package for Ubuntu, but my VM is giving me headaches at the moment and I can't check...
According to this question at AskUbuntu:
It turns out that the APT installations put the libraries under /usr/lib/x86_64-linux-gnu and PIL will search for them in /usr/lib/. So you have to create symlinks for PIL to see them.
In other words, PIL apparently doesn't understand modern Ubuntu, or in fact most 64-bit linuxes.
What you probably want to do is:
Switch to Pillow as MattDMo suggests,
Use an Ubuntu package for PIL (python-imaging) instead of trying to install via pip, or
Do both—use an Ubuntu package for Pillow, if there is one.
Checking on packages.ubuntu.com, the python-imaging package is in fact Pillow 2.0.0 on Saucy (13.10). In fact, it's Pillow on anything Raring or later; it's only people still using 12.x or earlier versions who are stuck with PIL. So, if you just do this:
$ sudo pip uninstall PIL
$ sudo apt-get install python-imaging
… that will get you Pillow, and pull in any dependencies it needs, all in one step.
If you don't want to do any of those, you should first reconsider that decision because it's probably a mistake, and then look at the workarounds suggested on that answer. In particular, symlinking the libs you installed into your /usr/lib directory is probably what you need. So, for example:
$ sudo pip uninstall PIL
$ sudo apt-get install libjpeg-dev
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
$ # repeat for the various other libraries, but JPEG is the one you asked about
$ sudo pip install PIL
Alternatively, you could patch PIL itself, as some of the answers on the linked question show. In particular, add these two lines:
add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
add_directory(library_dirs, "/lib/x86_64-linux-gnu")
… after the lines that add /usr/local/lib and /usr/lib.
However, if you're going to use a patched PIL, why not use Pillow, which has already solved this problem and many others?
Additional notes for Mac OS X
On Mac OS X you will usually install additional software such as
libjpeg or freetype with the "fink" tool, and then it ends up in
"/sw". If you have installed the libraries elsewhere, you may have
to tweak the "setup.py" file before building.
Additional notes for Windows
On Windows, you need to tweak the ROOT settings in the "setup.py"
file, to make it find the external libraries. See comments in the
file for details.
Make sure to build PIL and the external libraries with the same
runtime linking options as was used for the Python interpreter
(usually /MD, under Visual Studio).
Note that most Python distributions for Windows include libraries
compiled for Microsoft Visual Studio. You can get the free Express
edition of Visual Studio from:
http://www.microsoft.com/Express/
To build extensions using other tool chains, see the "Using
non-Microsoft compilers on Windows" section in the distutils handbook:
http://www.python.org/doc/current/inst/non-ms-compilers.html
For additional information on how to build extensions using the
popular MinGW compiler, see:
http://mingw.org (compiler)
http://sebsauvage.net/python/mingw.html (build instructions)
http://sourceforge.net/projects/gnuwin32 (prebuilt libraries)

Need help installing PIL to use Django ImageField

I am a novice at these things. I have been all over the internet looking for a way to get around this error :
unable to execute gcc-4.2: No such file or directory
error: command 'gcc-4.2' failed with exit status 1
When trying to install the Python Image Library, I get this error each time I run :
python setup.py install
I have tried a number of solutions given on this site and others across the web and no luck.
I have tried installing PIL with Macports which seemed to work but when I ran syncdb on my Django models it told me to install PIL.
Kind of lost at the moment. Is there anyone who has a tested, fool-proof way to get around this problem?
In my experience PIL is a nightmare to build and install unless you are using pip. Try creating a virtualenv and then installing PIL inside it with:
pip install PIL
I have PIL running fine on Snow Leopard with Python 2.7 out of MacPorts with this technique.
If you have trouble getting virtualenv up and running, I suggest virtualenv-burrito, which will set everything up for you automatically.

Symlinking PIL from site packages on Snow Leopard to a virtualenv with no-site-packages not working

I have a virtualenv with --no-site-packages and am having all sorts of issues installing PIL in the virtualenv. The global PIL works fine. I'm trying to get this working by symlinking to PIL in the global site packages, which I know works. I tried:
ln -s /Library/Python/2.6/site-packages/PIL ~/my_virtualenv/lib/python2.6/site-packages/PIL
When I then try to import PIL from Python, that works fine. However I can't run import Image but this works for the system Python. I also tried just copying the directory wholesale, but no dice there either.
Any ideas on how to debug this? How does PIL export Image to the global "module space?"
Update: Thanks to #Sentinel's persistance, I was able to solve this problem. Examining the trace when installing PIL, I noticed a bunch of lines like so:
ld: warning: in /opt/local/lib/libjpeg.dylib, missing required architecture ppc in file
ld: warning: in /opt/local/lib/libz.dylib, missing required architecture ppc in file
Those are actual all the errors that are left, but originally there were others complaining about how I didn't have libjpeg for i386 or x64 architectures as well. So I backed up, removed the libjpeg I had installed to /usr/local/lib and just used macports to install the universal binaries (basically following the instructions at http://passingcuriosity.com/2009/installing-pil-on-mac-os-x-leopard/). Figuring this is what was causing the problem, libjpeg wasn't compiled for the architecture I needed. After doing that, I then installed the Imaging library and then everything worked -- no symlinking required. And now I can go to bed without thinking about this anymore, even if it took 4 hours to figure out. :)
Install the development libraries (jpeg, zip, etc.), then use the virtualenv (adding setuptools or pip to it as necessary) to install PIL into the virtualenv itself.

Installing PIL on Snow Leopard

Hey, i have a problem installing PIL on Snow.
I have a clean installation of macports after the upgrade to SL and installed from source the jpeg library following the OS specific installation instructions. Installing PIL with pip goes well but when i try to import the _imaging module i get the following message:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): no suitable image found. Did find:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so: mach-o, but wrong architecture
MacPorts already has a PIL port that will do all the work for you!
sudo port install py26-pil
You should first go into the site-packages directory and elsewhere to remove the stuff you installed manually, though. MacPorts will install all the necessary dependent libraries.
PIL on Mac OS X has been a pain point for many of my friends. These instructions seem to often help speedup the enlightenment process:
http://passingcuriosity.com/2009/installing-pil-on-mac-os-x-leopard/
Good luck!
I had the same problems, and actually created a small tutorial on how to resolve this.
getting a working copy of PIL, libjpeg and Imaging on Snow Leopard or even Lion
My default version of Python was still on 2.6 so I had to switch to 2.7
defaults write com.apple.versioner.python Version 2.7
get v8c of jpeg
cd into jpeg directory.
sudo make clean
CC="gcc -arch i386" ./configure --enable-shared --enable-static
make
sudo make install
get imaging i am using 1.1.6
untar
cd into imaging
sudo rm -rf build
vi setup.py
JPEG_ROOT = libinclude(“/usr/local/lib”)
sudo python setup.py install
And it’s that simple
Run your python interpreter,
import PIL
import _imaging
import Image
if all is well, then your all set.
I'm not entirely certain (I use a PC myself), but I think that you might find something interesting here
May the force be with you

Categories