error importing PIL

434 views
Skip to first unread message

mike

unread,
May 17, 2011, 2:16:21 AM5/17/11
to PyInstaller
Hi all,

I had got an Import error on PIL (far below). For whatever reason, my
installation (which is the most recent, and downloaded from the PIL
website) requires "from PIL import Image" instead of "import Image".
(see my patch file below, everything between the starred lines).

This could be a recent change on PIL's part (or a misconfiguration on
my machine). Is there a way to automatically check for both? Or if
PIL is no longer supporting "import Image", perhaps updating the hook?

Cheers
Mike


**************************
Index: PyInstaller/hooks/shared_PIL_Image.py
===================================================================
--- PyInstaller/hooks/shared_PIL_Image.py (revision 1406)
+++ PyInstaller/hooks/shared_PIL_Image.py (working copy)
@@ -18,7 +18,9 @@
hiddenimports = []

def install_Image(lis):
- import Image
+ from PIL import Image
+
# PIL uses lazy initialization.
# you candecide if you want only the
# default stuff:
***************************


--------
Traceback (most recent call last):
File "pyinstaller.py", line 94, in <module>
run_build(opts, spec_file)
File "pyinstaller.py", line 50, in run_build
PyInstaller.build.main(spec_file, **opts.__dict__)
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
build.py", line 1494, in main
build(specfile, buildpath)
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
build.py", line 1393, in build
execfile(spec)
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/MyApp/
MyApp.spec", line 3, in <module>
pathex=['/Users/mjpan/Downloads/python/pyinstaller.20110517'])
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
build.py", line 332, in __init__
self.__postinit__()
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
build.py", line 282, in __postinit__
self.assemble()
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
build.py", line 400, in assemble
analyzer.analyze_script(script)
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
mf.py", line 568, in analyze_script
return self.analyze_r('__main__')
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
mf.py", line 460, in analyze_r
newnms = self.analyze_one(name, nm, imptyp, level)
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
mf.py", line 521, in analyze_one
mod = self.doimport(nm, ctx, fqname)
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
mf.py", line 609, in doimport
hooks = __import__('PyInstaller.hooks', globals(), locals(),
[hookmodnm])
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
hooks/hook-PIL.Image.py", line 29, in <module>
from PyInstaller.hooks.shared_PIL_Image import *
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
hooks/shared_PIL_Image.py", line 33, in <module>
install_Image(hiddenimports)
File "/Users/mjpan/Downloads/python/pyinstaller.20110517/PyInstaller/
hooks/shared_PIL_Image.py", line 21, in install_Image
import Image
ImportError: No module named Image

Hartmut Goebel

unread,
May 17, 2011, 4:07:16 AM5/17/11
to pyins...@googlegroups.com
Am 17.05.2011 08:16, schrieb mike:
> I had got an Import error on PIL (far below). For whatever reason, my
> installation (which is the most recent, and downloaded from the PIL
> website) requires "from PIL import Image" instead of "import Image".
> (see my patch file below, everything between the starred lines).
I really wonder about this: According to PyInstaller/hooks/hook-Image.py
and PyInstaller/hooks/hook-PIL.Image.py PIL can be imported by either
"import Image" or "from PIL import Image". This is since PIL puts a file
"PIL.pth" into site-packages.

I just checked and PIL.pth is still in 1.1.7 source kit and in SVN (both
trunk and 1.1.7). Can you please check whether PIL.pth is in you
site-packages directory.

--
Schönen Gruß - Regards
Hartmut Goebel
Dipl.-Informatiker (univ.), CISSP, CSSLP

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen
http://www.goebel-consult.de

Monatliche Kolumne: http://www.cissp-gefluester.de/
Goebel Consult mit Mitglied bei http://www.7-it.de


mike

unread,
May 17, 2011, 4:15:18 AM5/17/11
to PyInstaller
Looks like this may be a Mac only issue? For me, its a egg directory,
there's no PIL.pth.
As for what hook-PIL.Image says, I don't know. My error isn't coming
out of hook-PIL.Image though.

Cheers
Mike

----

$ ls /Library/Python/2.6/site-packages
...
PIL-1.1.7-py2.6-macosx-10.6-universal.egg
...

$ ls /Library/Python/2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.6-
universal.egg/
EGG-INFO _imaging.pyc
_imagingft.pyc _imagingmath.pyc _imagingtk.pyc
PIL _imaging.so
_imagingft.so _imagingmath.so _imagingtk.so
_imaging.py _imagingft.py
_imagingmath.py _imagingtk.py





On May 17, 4:07 pm, Hartmut Goebel <h.goe...@goebel-consult.de> wrote:
> Am 17.05.2011 08:16, schrieb mike:> I had got an Import error on PIL (far below).  For whatever reason, my
> > installation (which is the most recent, and downloaded from the PIL
> > website) requires "from PIL import Image" instead of "import Image".
> > (see my patch file below, everything between the starred lines).
>
> I really wonder about this: According to PyInstaller/hooks/hook-Image.py
> and PyInstaller/hooks/hook-PIL.Image.py PIL can be imported by either
> "import Image" or "from PIL import Image". This is since PIL puts a file
> "PIL.pth" into site-packages.
>
> I just checked and PIL.pth is still in 1.1.7 source kit and in SVN (both
> trunk and 1.1.7). Can you please check whether PIL.pth is in you
> site-packages directory.
>
> --
> Schönen Gruß - Regards
> Hartmut Goebel
> Dipl.-Informatiker (univ.), CISSP, CSSLP
>
> Goebel Consult
> Spezialist für IT-Sicherheit in komplexen Umgebungenhttp://www.goebel-consult.de
>
> Monatliche Kolumne:http://www.cissp-gefluester.de/
> Goebel Consult mit Mitglied beihttp://www.7-it.de
>
>  smime.p7s
> 6KViewDownload

Martin Zibricky

unread,
May 17, 2011, 5:06:31 AM5/17/11
to pyins...@googlegroups.com
Hartmut Goebel píše v Út 17. 05. 2011 v 10:07 +0200:

> I really wonder about this: According to
> PyInstaller/hooks/hook-Image.py
> and PyInstaller/hooks/hook-PIL.Image.py PIL can be imported by either
> "import Image" or "from PIL import Image". This is since PIL puts a
> file
> "PIL.pth" into site-packages.

Could it be becasue pyinstaller can't handle *.pth files?

Hartmut Goebel

unread,
May 17, 2011, 5:16:38 AM5/17/11
to pyins...@googlegroups.com
Am 17.05.2011 11:06, schrieb Martin Zibricky:
> Could it be becasue pyinstaller can't handle *.pth files?
The error mike described occurs when handling the hook, so it's a build
time issue: the import fails.
AFAIK there should be no need to handle *.pth files, since this is done
transparently by Python.

A test on my system shows all these are working:
$ python -c 'import Image'
$ python -c 'import PIL.Image'
$ python -c 'from PIL import Image'

--
Schönen Gruß - Regards
Hartmut Goebel
Dipl.-Informatiker (univ.), CISSP, CSSLP

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen

http://www.goebel-consult.de/blog/

Hartmut Goebel

unread,
May 17, 2011, 5:20:08 AM5/17/11
to pyins...@googlegroups.com
Am 17.05.2011 10:15, schrieb mike:
> Looks like this may be a Mac only issue? For me, its a egg directory,
> there's no PIL.pth.
IC.

I'll change the hook to support both. This should not harm.

BTW: Please to not full quote. This is a mailinglists and all messages
get archived. Thanks.

Reply all
Reply to author
Forward
0 new messages