← Back to team overview

openerp-india team mailing list archive

Re: [Bug 930550] Re: 'import Image' instead of 'from PIL import Image' in point_of_sale.py

 

On 02/20/2012 02:36 PM, Ronald Portier (Therp) wrote:
> Problem is that this is not working everywhere.
> 
> And why is this the "clean" way of importing?

I understand how the adjective "clean" may be rather subjective.
The thing is, importing PIL from its own namespace is the standard Python way
of importing external packages (or stdlib packages for that matter).
PIL historically uses a distutils hack to enable "Import Image" to work.


> Import Image is what the documentation says:
> 
> http://www.pythonware.com/library/pil/handbook/introduction.htm

In fact, the documentation of PIL itself is rather confusing, it uses "Import
Image" in the Tutorial section, and "from PIL import Image" in other places, e.g:
    http://www.pythonware.com/library/pil/handbook/image.htm

This seems to indicate that the author intended both methods to work in all
cases, but unfortunately the way this is done is not compatible with setuptools
and eggs (easy_install). Or so I understand.

This incompatibility is apparently one of the reasons for the creation of the
Pillow fork, and is explained here:
    http://mail.python.org/pipermail/image-sig/2010-August/006480.html


> I had to revert this patch/update to get my server starting again...

If you search the source code of the official distribution of OpenERP (server
and addons) for "import Image" you will see the reason why this bug was
reported: everywhere we use "from PIL import Image", except for POS.
The patch for current bug should therefore not have created the problem, it
would normally have been there all the time.

One workaround for the PIL setuptools issue would be to install PIL using
"python setup.py install" or the binary package for your distribution instead
of "easy_install".. perhaps you can confirm this?

Now I imagine we could replace every PIL-related import with this
pattern:

  try:
     from PIL import Image
  except ImportError:
     import Image

which would keep it compatible with Pillow and still compatible with
easy_install'd PIL packages.
That looks a bit overkill though, even if it could be abstracted away... might
be worth discussing over a merge proposal...

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/930550

Title:
  'import Image' instead of 'from PIL import Image'  in point_of_sale.py

Status in OpenERP Addons (modules):
  Fix Released

Bug description:
  While 'import Image' works with the standard PIL installation, it is
  not supported and not compatible Pillow, the friendly PIL fork.

  PIL is imported correctly in all other places:
  find -name "*.py" -print0 |xargs -0 grep 'import Image'

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/930550/+subscriptions


References