最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【或许解决】x64的Win7的Python通过PyInstaller打包的exe运行时,在别人的Win7下运行时出错:ImportError: The _imaging C module is not installed

Python crifan 6311浏览 0评论

【问题】

python的程序,打包成了exe:

BlogsToWordpress_v16.9_2013-03-11_noGUI_windows.exe

别人运行,结果出错:

win7 運行exe程序,出現以下提示:請問什麼原因?
C:\>blogsto
Traceback (most recent call last):
  File "", line 12, in 
  File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.py", line 386, in importHook
  File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
  File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\out00-PYZ.pyz\PIL.PalmImagePlugin
", line 92, in   File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\out00-PYZ.pyz\PIL.PalmImagePlugin
", line 82, in build_prototype_image
  File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\out00-PYZ.pyz\PIL.Image", line 17
63, in new  File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\out00-PYZ.pyz\PIL.Image", line 37
, in __getattr__
ImportError: The _imaging C module is not installed

【解决过程】

1.去查了查之前通过PyInstaller打包exe时:

【记录】用PyInstaller把Python代码打包成单个独立的exe可执行文件

所生成的警告文件:

pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\warnBlogsToWordpress.txt

内容,是:

W: no module named org (delayed import by xml.sax)

W: no module named _dummy_threading (top-level import by dummy_threading)

W: no module named cl (delayed, conditional import by aifc)

W: no module named pwd (delayed, conditional import by posixpath)

W: no module named org (top-level import by pickle)

W: no module named Carbon (delayed import by plistlib)

W: no module named posix (delayed, conditional import by __main__)

W: no module named iconv_codec (top-level import by BeautifulSoup)

W: no module named fcntl (conditional import by subprocess)

W: no module named MacOS (delayed import by platform)

W: no module named readline (delayed import by pdb)

W: no module named AES (delayed, conditional import by archive)

W: no module named _scproxy (conditional import by urllib)

W: no module named pwd (delayed import by getpass)

W: no module named posix (delayed, conditional import by iu)

W: no module named EasyDialogs (conditional import by getpass)

W: no module named termios (top-level import by getpass)

W: no module named gestalt (delayed import by platform)

W: no module named org (top-level import by copy)

W: no module named _imaging_gif (top-level import by PIL.GifImagePlugin)

W: no module named fcntl (top-level import by tempfile)

W: no module named cjkcodecs (top-level import by BeautifulSoup)

W: no module named readline (delayed, conditional import by cmd)

W: no module named java (delayed import by platform)

W: no module named cl (delayed import by aifc)

W: no module named xmlparse (top-level import by pyexpat)

W: no module named xmltok (top-level import by pyexpat)

W: no module named java (conditional import by xml.sax._exceptions)

W: no module named _emx_link (conditional import by os)

W: no module named posix (conditional import by os)

W: no module named ICCProfile (delayed, conditional import by PIL.PngImagePlugin)

W: no module named rourl2path (conditional import by urllib)

W: no module named vms_lib (delayed, conditional import by platform)

W: no module named SOCKS (top-level import by ftplib)

W: no module named _xmlplus (top-level import by xml)

W: no module named Crypt (delayed, conditional import by __main__)

W: no module named AES (delayed, conditional import by __main__)

W: delayed  exec statement detected at line 0 – bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc)

W: delayed  eval hack detected at line 0 – bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc)

W: delayed  eval hack detected at line 0 – bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc)

W: delayed  __import__ hack detected at line 0 – optparse (D:\tmp\dev_install_root\Python27_x64\lib\optparse.pyc)

W: delayed  __import__ hack detected at line 0 – PIL.Image (D:\tmp\dev_install_root\Python27_x64\lib\site-packages\PIL\Image.pyc)

W: delayed conditional __import__ hack detected at line 0 – doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc)

W: delayed  exec statement detected at line 0 – doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc)

W: delayed conditional __import__ hack detected at line 0 – doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc)

W: __all__ is built strangely at line 0 – tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc)

W: __all__ is built strangely at line 0 – tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc)

W: delayed  __import__ hack detected at line 0 – pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc)

W: delayed  __import__ hack detected at line 0 – pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc)

W: delayed  __import__ hack detected at line 0 – encodings (D:\tmp\dev_install_root\Python27_x64\lib\encodings\__init__.pyc)

W: __all__ is built strangely at line 0 – dummy_threading (D:\tmp\dev_install_root\Python27_x64\lib\dummy_threading.pyc)

W: __all__ is built strangely at line 0 – dis (D:\tmp\dev_install_root\Python27_x64\lib\dis.pyc)

W: __all__ is built strangely at line 0 – hashlib (D:\tmp\dev_install_root\Python27_x64\lib\hashlib.pyc)

W: delayed conditional eval hack detected at line 0 – warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc)

W: delayed conditional __import__ hack detected at line 0 – warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc)

W: delayed  __import__ hack detected at line 0 – email (D:\tmp\dev_install_root\Python27_x64\lib\email\__init__.pyc)

W: delayed  exec statement detected at line 0 – pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc)

W: delayed conditional eval hack detected at line 0 – pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc)

W: delayed  eval hack detected at line 0 – pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc)

W: delayed conditional eval hack detected at line 0 – pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc)

W: delayed  eval hack detected at line 0 – pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc)

W: delayed conditional exec statement detected at line 0 – iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc)

W: delayed conditional exec statement detected at line 0 – iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc)

W: __all__ is built strangely at line 0 – collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc)

W: delayed  exec statement detected at line 0 – collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc)

W: delayed conditional __import__ hack detected at line 0 – unittest.main (D:\tmp\dev_install_root\Python27_x64\lib\unittest\main.pyc)

W: delayed conditional __import__ hack detected at line 0 – unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc)

W: delayed conditional __import__ hack detected at line 0 – unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc)

W: delayed  __import__ hack detected at line 0 – unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc)

W: __all__ is built strangely at line 0 – __future__ (D:\tmp\dev_install_root\Python27_x64\lib\__future__.pyc)

W: delayed  __import__ hack detected at line 0 – xml.sax (D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\__init__.pyc)

W: delayed  eval hack detected at line 0 – gettext (D:\tmp\dev_install_root\Python27_x64\lib\gettext.pyc)

其中,就有几个和PIL相关的:

W: no module named _imaging_gif (top-level import by PIL.GifImagePlugin)

W: no module named ICCProfile (delayed, conditional import by PIL.PngImagePlugin)

W: delayed  __import__ hack detected at line 0 – PIL.Image (D:\tmp\dev_install_root\Python27_x64\lib\site-packages\PIL\Image.pyc)

不知道是不是和这个有关。

2.后来参考:

"The _imaging C module is not installed"

解释的比较清楚:

PIL中,包括两块:

  • 一堆的Python库,放在PIL子文件夹下;
  • 一个二进制扩展库,叫_imaging,此文件名,不同平台,名字不同:
    • 比如有的是_imaging.pyd, _imaging.dll,_imaging.so等等

如果Python导入_imaging库失败,其他部分,其他的,大多数模块,都还是可以正常工作的。

还是可以通过PIL,去解析常见的各种图片的;

但是如果其中要用到了_imaging的话,则如果找不到,当然会出现ImportError了。

 

Windows平台下,对应的_imaging模块文件是:

_imaging.pyd(少数情况下,是_imaging.dll)

 

3.此处,由于不太清楚,别人的win7的环境具体如何,所以,也只能是试着找找能否找到错误原因了。

后来去:

\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\out00-Analysis.toc

中,找到了,对应的PIL和_imaging相关的部分:

(‘pyi_rth_PIL_Image’, ‘D:\\tmp\\tmp_dev_root\\python\\tutorial_summary\\make_exe\\pyinstaller-2.0\\support/rthooks/pyi_rth_PIL_Image.py’, ‘PYSOURCE’),

….

(‘PIL._imaging’, ‘D:\\tmp\\dev_install_root\\Python27_x64\\lib\\site-packages\\PIL\\_imaging.pyd’, ‘EXTENSION’),

所以,看起来,是PyInstaller打包exe时,已经集成了对应的库了。

所以,应该不存在,缺少了对应的PIL和_imaging库的问题。

4.后来参考:

The _imaging C module is not installed (on windows)

看起来像是:

我当前的系统是Win7 x64,

写的Python程序锁用到的PIL,也是对应的,编译好的x64的;

通过PyInstaller打包后,打包的,都是x64版本的Python,包括PIL(和_imaging)

别人,将此exe,放到其32位的win7上运行,导致无法正常使用,无法找到对应的

32位的PIL库,所以出错了。

 

如果是这样的话,那么就麻烦了:

需要我单独再次重新找个32位的win7,重新安装32位的PIL,然后再去重新打包为exe,然后拿到别人的32位的win7下,估计就可以了。

 

【总结】

总之,目前看起来,即使安装上述办法去解决,或许可以解决,但也还是比较麻烦的。

转载请注明:在路上 » 【或许解决】x64的Win7的Python通过PyInstaller打包的exe运行时,在别人的Win7下运行时出错:ImportError: The _imaging C module is not installed

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 谢谢楼主的定位分析,帮了很大的忙
    aliance11年前 (2013-12-06)回复
92 queries in 0.200 seconds, using 22.18MB memory