#6054 closed (fixed)
PIL import error
Reported by: | Nebojsa Djordjevic - nesh | Owned by: | nobody |
---|---|---|---|
Component: | Validators | Version: | dev |
Severity: | Keywords: | PIL | |
Cc: | nesh@… | Triage Stage: | Design decision needed |
Has patch: | no | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I tried to use ImageField
but I got a error that PIL is not installed.
Problem is -- I have PIL installed (easy_instal PIL) and it is working ... and after some hunting I found this
try: from PIL import Image except ImportError: e.add(opts, '"%s": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .' % f.name)
this assume that PIL is in PIL package but, at least in my system, PIL stuff is in site-packages so import Imaging
works.
Temporary I fixed it like this:
try: from PIL import Image except ImportError: try: import Image except ImportError: e.add(opts, '"%s": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .' % f.name)
so it works now.
Is this my system weirdness or something else?
Change History (11)
comment:1 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
It seems that there is something wrong with easy_install
which installs PIL in the root namespace, installing from sources fixes this, strange.
comment:3 by , 16 years ago
Needs tests: | set |
---|---|
Resolution: | invalid |
Status: | closed → reopened |
Triage Stage: | Unreviewed → Design decision needed |
This isn't a Django problem.
In my opinion, this is a django issue. If there are two options of accessing a module both of them should be supported.
On a shared host if the "non PIL" option is only one avaliable you can't do anything. The fix requires ONLY 3 places updated.
core\files\image.py , core\management\validation.py , forms\fields.py
try: import Image except ImportError: from PIL import Image
comment:4 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
from PIL import Image
is a completely legal (and documented) way of importing PIL. If this doesn't work, then your version of PIL isn't installed correctly. If PIL isn't installed correctly, Django can't be expected to fix up the mess. The fix here is for you to fix your PIL install.
comment:5 by , 15 years ago
Keywords: | PIL added |
---|
The PIL docs are ambiguous. In the tutorial, it uses "import Image". I would guess this is a bug in the tutorial, anyway, but I guess we should warn them.
comment:6 by , 15 years ago
Or, perhaps, the error message given on validate could warn about this issue until it's solved.
comment:7 by , 15 years ago
In the mean time, a quick fix which saves you screwing around with multiple core django files and will allow both recognised PIL import behaviours:
>>> import Image
and
>>> from PIL import Image
is to write a PIL.py file in the egg directory which imports the necessary PIL modules. For Django which requires "Image" and "ImageFile" as pointed out by haloween the following command should suffice:
junkafarian:~ junkafarian$ echo "import Image, ImageFile" >> /path/to/env/site-packages/PIL-[version].egg/PIL.py
The major problem with this hack is that you will need to include all the modules you require for the project in the import statement (which may be more than just "Image" and "ImageFile")
comment:8 by , 15 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
(As other have noted) installing the latest (1.1.7) version of PIL using easy_install
results in the from PIL import Image
failing (import Image
works).
While I agree that this is probably a PIL packaging problem (or ambiguous documentation on their part), from the perspective of making Django "just work", it (Django) should really try both imports. This is a trivial change and will make people who want to use setuptools to install Django and dependencies far less frustrated. The current limitation means that you can't just create a setup.py for your project with deps on Django and PIL and expect it to actually work. For me that's enough to prohibit use of ImageField.
comment:9 by , 15 years ago
Confirming that, under OSX 10.5.8, using easy_install to install either 1.16 or the more recent 1.1.7 release of PIL, django breaks in a couple of ways. Specifically, I've been unable to use syncdb if I have an ImageField present in any INSTALLED_APPS model. This is because, as others have stated, Django only looks for a PIL package from which it can import the Image module.
This is obviously, in itself, not a Django problem, but a easy_install/PIL combination problem (its worth noting that using pip to install PIL results in a PIL package in site-packages), but it is somewhat of a show stopper for people who might be beginning development, as, to their awareness, they have installed PIL entirely correctly. Whether or not this is likely to affect production scenarios, I don't know, but I support the suggestions & attempts to patch the imports to look for Image et al in both locations outlined in the original ticket.
comment:10 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
This isn't a Django problem. The PIL documentation shows the use of Image being in PIL so the bug is either with your system or elsewhere.