Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21355 closed Bug (fixed)

Try importing _imaging from PIL namespace first.

Reported by: richardxia Owned by: akaariai
Component: Utilities Version: 1.6
Severity: Release blocker Keywords: pil pillow
Cc: preston@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Patch available at Fixes problem described in #20964.

On an OS X system with a Homebrew version of Python/PIL installed, the django/utils/image module encounters a hash collision error when trying to import _imaging, as described in #20964. Although that ticket was closed for not being a problem with Django, the ticket it references in the Homebrew project ( only resulted in removing PIL from the core Homebrew libraries without actually fixing the original import issue. Everyone in the Homebrew ticket discussion agrees that pillow should be used in place of PIL, but because Django isn't officially removing support for PIL until 1.8, I believe that this problem deserves to be fixed in time for 1.6.

In my patch, I attempt to import _imaging from the PIL namespace first, which prevents the hash collision error because the _imaging module will imported using the same filesystem path as when imported through the earlier from PIL import Image statement. If _imaging isn't available under PIL, then it attempts to import _imaging directly just as did before. This allows PIL to be properly imported in my setup (OS X 10.8, Homebrew Python/PIL) and should still be compatible with environments in which the PIL namespace isn't available.

Change History (10)

comment:1 Changed 3 years ago by ptone

  • Cc preston@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by akaariai

I'll close this as wontfix. If you must use Homebrew, then use Pillow.

ptone: I see you are in cc - if you are planning on doing something to this, just revert my wontfix.

comment:3 Changed 3 years ago by akaariai

  • Resolution set to wontfix
  • Status changed from new to closed

comment:4 Changed 3 years ago by leo+django@…

  • Resolution wontfix deleted
  • Status changed from closed to new

We actually have the exact same issue on a CentOS 6.4 with python-imaging (for PIL) and mod_wsgi both from CentOS. We are trying to use Django 1.6, but when using a django.forms.ImageField we are getting the error message:

ImproperlyConfigured: The '_imaging' module for the PIL could not be imported: No module named _imaging

The fix by richardxia (trying "from PIL import _imaging as PIL_imaging" first) works for us. I don't see why this shouldn't go into the official release as it seems harmless and works exactly the same as the PILImage import just a few lines above. Considering our pretty clean CentOS 6 simple setup I don't think we will be the only ones that run into this as more people migrate to Django 1.6.

Can the "wontfix" decision be re-evaluated?

comment:5 Changed 3 years ago by anonymous

  • Version changed from 1.6-beta-1 to 1.6

comment:6 Changed 3 years ago by akaariai

OK, so it seems this isn't Homebrew issue. I'll mark this as release blocker for 1.6. I am not sure what we should do about this. If the patch really is safe (I can't tell) then we should likely backpatch.

By marking this as release blocker I want to assure that we at least consider doing something to this before 1.6.1.

comment:7 Changed 3 years ago by akaariai

  • Severity changed from Normal to Release blocker
  • Triage Stage changed from Unreviewed to Accepted

comment:8 Changed 3 years ago by akaariai

  • Owner changed from nobody to akaariai
  • Status changed from new to assigned

I think I will just commit the fix. The fix seems safe, and it seems there are some setups where the fix is needed.

Any objections?

comment:9 Changed 3 years ago by Anssi Kääriäinen <akaariai@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 5725236c3ee4323203aa681cb54d1ff1d7f376df:

Fixed #21355 -- try importing _imaging from PIL namespace first.

comment:10 Changed 3 years ago by Anssi Kääriäinen <akaariai@…>

In 6cd5c67b694b3469817e38d02f79ddef7c2a7132:

[1.6.x] Fixed #21355 -- try importing _imaging from PIL namespace first.

Backport of 5725236c3e from master

Note: See TracTickets for help on using tickets.
Back to Top