Py2App将PIL Dylibs放在Zip文件中 [英] Py2App Placing PIL Dylibs in Zip file

查看:95
本文介绍了Py2App将PIL Dylibs放在Zip文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Python Imaging Library(PIL)并使用Py2app打包的python应用程序。在应用程序目录目录中找到了Numpy dylib:

I have an python application that uses the Python Imaging Library (PIL) and is packaged using Py2app. Numpy dylibs are found in the app contents directory:

demo.app/Contents/Resources/lib/python3.8/numpy/.dylibs/libgcc_s.1.dylib

在这里可以搜索并签名PIP dylib在 python3.8.zip 文件

where they can be searched for and signed but PIP dylibs are inside a python3.8.zip file

demo.app/Contents/Resources/lib/python3.zip -> ./PIL/.dylibs/libfreetype.6.dylib

其中一个必须解压,签名,并压缩它们。为什么会发生这种情况,以及如何防止这种情况发生,所以我不必区别对待?

where one would have to unzip, sign, and rezip them. Why does this happen and how do I prevent it so that I don't have to treat it different?

推荐答案

py2app 通过称为食谱 。它带有某些软件包的内置配方,包括 numpy ,这就是为什么numpy被排除在 .zip 文件之外的原因。 (这是内置的numpy食谱。

py2app implements special handling of certain packages via a mechanism called "recipes". It comes with built-in recipes for certain packages including numpy, which is why numpy is excluded from the .zip file. (Here's the built-in numpy recipe.)

除了内置食谱外,您还可以定义自己的食谱供py2app使用。只需定义一个具有 check 方法的类,然后将其作为属性修补到 py2app.recipes

In addition to the built-in recipes, you can define your own recipes for py2app to use. Just define a class that has a check method, and monkey-patch it as an attribute onto py2app.recipes:

# In setup.py

class PIL_recipe:
    def check(self, cmd, mf):
        m = mf.findNode("PIL")
        if m is None or m.filename is None:
            return None

        # Exclude from site-packages.zip
        return {"packages": ["PIL"]}

py2app.recipes.PIL = PIL_recipe()

...

setup(...)

如果需要要使用几个库来做到这一点,您可以推广这个技巧,以便它不会硬编码包的名称:

If you need to do this with several libraries, you can generalize this trick so that it doesn't hard-code the name of the package:

class ExcludeFromZip_Recipe(object):
    def __init__(self, module):
        self.module = module

    def check(self, cmd, mf):
        m = mf.findNode(self.module)
        if m is None:
            return None

        # Don't put the module in the site-packages.zip file
        return {"packages": [self.module]}

for module in ['PIL', 'skimage', 'sklearn', 'jsonschema']:
    setattr( py2app.recipes, module, ExcludeFromZip_Recipe(module) )

免责声明:这是我过去解决此问题的方式。但是我不确定为什么您的zip文件命名为 python3.zip 而不是 site-packages.zip

Disclaimer: This is how I've solved this problem in the past. But I'm not sure why your zip file is named python3.zip instead of site-packages.zip.

这篇关于Py2App将PIL Dylibs放在Zip文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆