简体   繁体   English

PyInstaller +魔杖(ImageMagick)-缺少依赖项

[英]PyInstaller + Wand (ImageMagick) - missing dependencies

I've spent the past couple of days trying to figure out how to build a dep-free application out of a bunch of Python3.4 scripts I have. 在过去的两天中,我一直试图找出如何从我拥有的Python3.4脚本中构建无Dep的应用程序。 These include an import of wand , which requires ImageMagick to be installed on the machine. 其中包括导入wand ,这要求在计算机上安装ImageMagick
So far so good, the app ran from source code works fine both my dev environments (Debian8/Win10), finding all the necessary dependencies for the Wand module to properly operate. 到目前为止,从源代码运行的应用程序在我的开发环境(Debian8 / Win10)上都能正常工作,找到了Wand模块正常运行所需的所有依赖项。

Troubles come when I try to package the app with PyInstaller. 当我尝试使用PyInstaller打包应用程序时,会出现麻烦。
The build process works as expected, fetching the ImageMagick resources ( .dll s etc) and including them in the output directory alongside the other binaries, but when I run the app on machines without the IM library installed the import fails. 构建过程按预期方式工作,获取ImageMagick资源( .dll等),并将其与其他二进制文件一起包含在输出目录中,但是当我在未安装IM库的计算机上运行应用程序时,导入将失败。

So I went digging into the Wand source code, and realized that dependecies are looked for in global system paths (ie C:\\ProgramFiles). 因此,我深入研究了Wand源代码,意识到在全局系统路径(即C:\\ ProgramFiles)中寻找依赖项。 As a workaround, in my code I simply overridden the os.environ['MAGICK_HOME'] variable with './' instructing the module to fetch the dependencies in place. 作为一种解决方法,在我的代码中,我只是用'./'覆盖了os.environ['MAGICK_HOME']变量,以指示模块获取适当的依赖项。 And it worked, up to a point. 它一直有效到一定程度。

Now I can start the app: imports won't fail, the GUI is drawn and functionality is not affected. 现在,我可以启动该应用程序:导入不会失败,绘制GUI且功能不受影响。 Not until I trigger any Wand-involving action at least, because whenever I do the app crashes raising the following exception: 直到我至少触发任何涉及魔杖的动作,因为每当我这样做时,应用程序崩溃都会引发以下异常:

wand.exceptions.ConfigureError: RegistryKeyLookupFailed `CoderModulesPath' @ error/module.c/GetMagickModulePath/666

It seems clear that the lack of a proper installation system-wide results in broken registry calls (now testing on win), but unfortunately I'm not quite familiar with CTypes (or whatever is being used to bind to the ImageMagick library) and I'm not sure how to proceed on properly building a no-deps app. 显然,在整个系统范围内缺乏适当的安装会导致注册表调用中断(现在在win上进行测试),但是不幸的是,我对CTypes(或用于绑定到ImageMagick库的任何东西)不太熟悉我不确定如何继续正确构建无延迟应用程序。

As always the first question popping into mind is: am I missing something obvious here? 与往常一样,我想到的第一个问题是:我在这里遗漏了明显的东西吗?
If not, what would be your suggestions? 如果没有,您的建议是什么?
Thanks 谢谢

This is more of a comment, and not really an answer, but I would suggest the following... 这更多是评论,而不是真正的答案,但是我建议以下...

MAGICK_HOME MAGICK_HOME

It's wise to set the MAGICK_HOME environment variable. 设置MAGICK_HOME环境变量是明智的。 But I would suggest using os.path to resolve the systems absolute path; 但是我建议使用os.path来解析系统的绝对路径; as opposed to relative. 相对的。

os.environ['MAGICK_HOME'] = os.path.abspath('.')

Very minor, but helps. 很小,但有帮助。

.dll's etc .dll的等

Remember that IM is it's own ecosystem. 请记住,即时消息是它自己的生态系统。 It's true that wand only needs MagickWand & MagickCore libraries to run, but IM needs all the delegates/coders to be useful. 这是真的, wand只需要MagickWandMagickCore库运行,但IM所需要的一切代表/编码器是有用的。 Ensure everything is present, and double check QuickStart.txt . 确保所有内容都存在,然后再次检查QuickStart.txt

On your build system, it might be worth checking identify utility to see other paths that should be included included during PyInstallers bundle stage. 在您的构建系统上,可能值得检查identify实用程序以查看在PyInstallers捆绑包阶段应包括的其他路径。

identify -list Configure | grep PATH

On my Mac, I receive the following... 在Mac上,我收到以下信息...

CODER_PATH     /usr/local/lib/ImageMagick-6.9.5/modules-Q16/coders
CONFIGURE_PATH /usr/local/etc/ImageMagick-6/
DOCUMENTATION_PATH /usr/local/share/doc/ImageMagick-6
EXECUTABLE_PATH /usr/local/bin
FILTER_PATH    /usr/local/lib/ImageMagick-6.9.5/modules-Q16/filters
INCLUDE_PATH   /usr/local/include/ImageMagick-6
LIBRARY_PATH   /usr/local/lib/ImageMagick-6.9.5
SHARE_PATH     /usr/local/share/ImageMagick-6
SHAREARCH_PATH /usr/local/lib/ImageMagick-6.9.5/config-Q16

File policy.xml under CONFIGURE_PATH would be ideal to include to ensure your application protects against ImageTragick CONFIGURE_PATH下的policy.xml文件非常适合包含以确保您的应用程序免受ImageTragick的攻击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM