带有 PIL 的 Pyinstaller。导入错误:无法导入名称 _imaging

2024-03-11

我在运行包含枕头的已编译可执行文件时遇到问题。我使用了 pyinstaller,它似乎编译得很好,但是运行 exe 后,会抛出错误。似乎与引用“_imaging”而不是“Image”存在冲突。

首先,我觉得很奇怪pillow如何安装到PIL目录而不是pillow,并且模块也被引用为PIL。但我怀疑这与这个问题有什么关系。

然而,Python27\Lib\site-packages\PIL 中实际上并没有 _imaging.py 文件,我怀疑这可能是一个问题,因为 pyinstaller 使可执行文件需要它。不确定是否有某种方法可以将其从构建中排除。这可能是下一步。

诸如此类的问题this https://stackoverflow.com/questions/30203575/import-error-when-running-pyinstaller-app and this https://stackoverflow.com/questions/27503961/error-using-pillow-importerror-cannot-import-name-imaging已提出但未解决。有些人还提到在安装pillow之前未卸载PIL,但PIL肯定已卸载,并且我尝试了pillow的二进制文件和pip安装。

有什么建议么?

运行时错误:

Traceback (most recent call last):
  File "<string>", line 26, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.PngImagePlugin", line 40, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.Image", line 63, in <module>
ImportError: cannot import name _imaging

下面是 PIL.Image 文件的摘录,有问题的行是

from PIL import _imaging 作为核心

try:
    # If the _imaging C module is not present, Pillow will not load.
    # Note that other modules should not refer to _imaging directly;
    # import Image and use the Image.core variable instead.
    # Also note that Image.core is not a publicly documented interface,
    # and should be considered private and subject to change.
    from PIL import _imaging as core
    if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
        raise ImportError("The _imaging extension was built for another "
                          " version of Pillow or PIL")

from PIL import Image

这就是我在脚本中调用枕头的方式:

from PIL import Image

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

带有 PIL 的 Pyinstaller。导入错误:无法导入名称 _imaging 的相关文章

  • java webapp配置策略

    我的网络应用程序的一部分涉及上传图像文件 在生产服务器上 文件需要写入 somepath on Production server images 对于本地开发 我想将文件写入 some different path images 处理这些配
  • 通过更改 build.xml 和 ant.properties 生成 Android 代码覆盖率

    我一直在尝试为我的 android 测试项目生成 android 代码覆盖率 该项目测试包含外部 jar 的 android 项目 当我运行命令时 ant emma install debug test 它仅显示了 android 项目的覆
  • Android Studio 2.1.3 中构建错误

    我使用的是android studio 2 1 3 尽管清除了项目并再次重建 重新启动等 我还是收到以下错误 如何解决 错误 任务执行失败 app transformClassesWithJavaResourcesVerifierForDe
  • Visual Studio 2010环境变量

    我在 Windows 中设置了一个名为 SDK 的环境变量 我可以在 csproj 文件中以某种方式使用它吗 就像是
  • Visual Studio 2010:如何在解决方案中强制执行项目的构建顺序?

    我在 Visual Studio 2008 中没有遇到任何问题 但 VS 2010 似乎有问题 我敢打赌这可能是我的问题 我有一个包含 ASP NET 网站项目和一些 C 项目 BLL DAL NUnit 中的测试 的解决方案 我已将测试项
  • Gatsby v2 网站无法正确加载 CSS

    在我的开发环境中 该网站看起来符合预期 但是当我运行 gatsby build 时 我的 CSS 无法正确显示 如果我手动导航到另一个页面 则 CSS 按预期显示 没有错误 但我确实收到此警告 资源http localhost 9000 s
  • 在 xhtml 页面中显示版本和构建日期

    我想在 JSF 应用程序的页脚上显示构建版本和构建日期 这些页面是 XHTML 我正在寻找从 pom xml 或其他工件获取信息的方法 我发现以下使用 maven replace 插件 http www vineetmanohar com
  • 如何构建 Boost::program_options

    我想使用 boost program options 安装boost后 我认为我必须单独构建program options http www boost org doc libs 1 43 0 more getting started wi
  • 如何使用PIL读取原始图像?

    我有一个原始图像 其中每个像素对应一个 16 位无符号整数 我正在尝试使用 PIL Image fromstring 函数进行读取 如以下代码所示 if name main if len sys argv 4 print Error mis
  • matplotlib 中的低对比度图像(对比度拉伸)问题

    当读取低对比度图像时 它会自动采用以下示例 In 1 from PIL import Image In 2 import numpy as np In 3 import matplotlib pyplot as plt In 4 img I
  • PyPandoc 与 PyInstaller 结合使用

    我安装了 PyInstaller 来为我的 python 脚本创建可执行文件 效果很好 我使用 PyPandoc 创建 docx报告 当正常的 python 文件运行时 它也可以正常运行 但不能从 PyInstaller 生成的可执行文件运
  • Unity构建错误

    所以我制作了我的游戏并尝试构建它 我收到一些对我来说毫无意义的错误 这是错误 UnityEditor BuildPlayerWindow BuildMethodException 2 个错误 在 UnityEditor BuildPlaye
  • 如何在Ant中添加相当于java -D的系统属性

    我需要设置java Djava library path some path我想在运行 ant 脚本 构建 jar 时执行此操作 我想我必须使用
  • matplotlib 绘图,然后等待原始输入

    我正在尝试打开一系列 png 图 我希望能够在屏幕上查看绘图 然后收到提示 等待我 按 Enter 按回车键后 应显示下一个图 我见过很多类似的问题 Matplotlib 强制绘图显示然后返回主代码 https stackoverflow
  • 冻结(.exe)一个traitsUI程序,现实可行吗?

    我正在尝试使用 cx freeze 或 pyInstaller 冻结一个 TraitsUI 程序 该程序利用 Chaco Traits TraitsUI 以及较小程度的 mayavi 实际上可以取出 我需要它在 mac linux ubun
  • Pyinstaller --onefile 警告文件已存在但不应存在

    跑步时Pyinstaller onefile 并开始得到结果 exe 会出现多个弹出窗口 并显示以下警告 WARNING file already exists but should not C Users myuser AppData L
  • 属性错误:类型对象“图像”没有属性“打开”

    Exception in Tkinter callback Traceback most recent call last File C Python34 lib tkinter init py line 1482 in call retu
  • 如何在 Python 中将图像分割成多个部分

    我正在尝试使用 PIL 将一张照片分成多块 def crop Path input height width i k x y page im Image open input imgwidth im size 0 imgheight im
  • multiprocessing.freeze_support()

    为什么多处理模块需要调用特定的function http docs python org dev library multiprocessing html multiprocessing freeze support在被 冻结 以生成 Wi
  • 从内存中发送图像

    我正在尝试为 Discord 机器人实现一个系统 该系统可以动态修改图像并将其发送给机器人用户 为此 我决定使用 Pillow PIL 库 因为它对于我的目的来说似乎简单明了 这是我的工作代码的示例 它加载一个示例图像 作为测试修改 在其上

随机推荐