【问题标题】:python - pyinstaller "RuntimeWarning: Parent module 'PyInstaller.hooks.hook-PIL' not found while handling absolute import" and "tcl" related errorspython - pyinstaller“RuntimeWarning:处理绝对导入时找不到父模块'PyInstaller.hooks.hook-PIL'”和“tcl”相关错误
【发布时间】:2015-08-05 13:40:54
【问题描述】:

我在尝试使用pyinstaller 创建可执行文件时收到一条警告消息。安装Pillow 后出现此警告。以前我从来没有收到任何警告并且能够通过。

pyinstaller 得到的警告是:

7314 INFO: Analyzing main.py
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/hooks/hook-PIL.Image.py:14: RuntimeWarning: Parent module 'PyInstaller.hooks.hook-PIL' not found while handling absolute import
  from PyInstaller.hooks.shared_PIL_Image import *

此外,当我尝试运行位于 pyinstaller (dist/main/main) 创建的 dist 文件夹中的代码的可执行文件的 exe/consol 版本时,会显示这些。..

Traceback (most recent call last):
  File "<string>", line 26, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
    exec(bytecode, module.__dict__)
  File "/Users/..../build/main/out00-PYZ.pyz/PIL.PngImagePlugin", line 40, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
    exec(bytecode, module.__dict__)
  File "/Users/..../build/main/out00-PYZ.pyz/PIL.Image", line 53, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
    exec(bytecode, module.__dict__)
  File "/Users/..../build/main/out00-PYZ.pyz/FixTk", line 74, in <module>
OSError: [Errno 20] Not a directory: '/Users/.../dist/main/tcl'
logout

[Process completed]

所以,我尝试卸载pillow,安装tk tcl dev 版本。然后安装pillow。即使这样也没有帮助。

我也尝试重新安装pyinstaller,。也没有用

更新 1:

Pyinstaller/hooks 目录中似乎缺少 Pyinstaller.hooks.hook-PIL.py 文件。它在所有平台(Mac、windows 和 linux)上都丢失了。这是我在 Windows 上收到的警告/错误消息,与我在 mac 和 linux 上收到的相同。 后来我找到了一个link,上面写着它的just to need Python import machinery happy。所以我按说的那样创建。然后我在所有平台上都没有得到相同的错误,但是在 mac 上我仍然得到 PILImagePlugin,ImageFixTk 错误

【问题讨论】:

    标签: python macos tcl pyinstaller pillow


    【解决方案1】:

    tcl 的解决方案:

    我发现出了什么问题,.. 我在OSX 上遇到的每个问题都是OS 本身(确切地说是macport)。默认情况下,Python 随 mac OS 一起提供。而且这个版本的python可能对学习基本的python有用,但不适合开发目的。

    安装 brew 的 python 有帮助。我关注了这个SO link。完成这些之后,我仍然遇到错误。后来我不得不更改/etc/paths 上的路径。基本上重新排列它们应该可以工作。但那时我还是没有做对。

    然后我不得不更改适用于大多数用户的.bash_profile,但我仍然获得了 mac 版本的 python 和 pip,而不是 brews 版本的 python。

    最后我不得不重新启动机器几次并重复执行/etc/paths.bash_profile 步骤以获得系统范围的效果以接受 brews 版本的 python 和 pip


    PIL 的解决方案:

    只需添加一个名为hook-PIL.py 且内容为空的文件即可达到目的。我找到了一个link,它的钩子文件内容为pyinstaller

    创建地点

    ma​​c 版: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/hooks/ 其实mac版不需要这一步。当我们通过 brew 安装 python 并更改路径时,您稍后尝试通过pip install 或从source packages 安装的所有内容往往会选择不同的路径。一切都会得到照顾。

    对于 Windows:C:\Python27\lib\site-packages\PyInstaller-2.1.1.dev0-py2.7.egg\PyInstaller\hooks

    **请在创建文件之前检查这是否是您机器上的有效路径,然后再创建文件。而且我不确定或者我不知道只是添加一个空文件是否是正确的方法。但它对我有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 2021-01-02
      • 2020-06-05
      • 2016-03-07
      • 2014-07-05
      • 2011-03-09
      • 1970-01-01
      相关资源
      最近更新 更多