我正在try 编译一个Tkinter应用程序作为MacOS的可执行文件.我试着用py2apppyinstaller.我几乎成功地使用了py2app,但它返回以下错误:

回溯

The Info.plist file must have a PyRuntimeLocations array containing string values for preferred Python runtime locations.  
These strings should be "otool -L" style mach ids; "@executable_stub" and "~" prefixes will be translated accordingly.

这是setup.py强的样子:

from setuptools import setup

APP = ['main.py']
DATA_FILES = ['config.json']
OPTIONS = {
    'argv_emulation': True
}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

这是目录 struct :

-modules/---__init.py__
|        | 
|        -- gui_module.py
|        |
|        -- scraper_module.py
|        |
|        -- app.ico
|
-config.json
|
-countries_list.txt
|
-main.py
|
-requirements.txt
|
-setup.py

如果你需要的话,我很乐意与你分享更多的细节和文件.

推荐答案

问题是,您需要为您的MacOS上的python框架提供一个可执行路径.所以我修改了Setup.py

Setup.py

from setuptools import setup

class CONFIG:
    VERSION = 'v1.0.1'
    platform = 'darwin-x86_64'
    executable_stub = '/opt/homebrew/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib' # this is important, check where is your Python framework and get the `dylib`
    APP_NAME = f'your_app_{VERSION}_{platform}'
    APP = ['main.py']
    DATA_FILES = [
        'config.json', 
        'countries_list.txt', 
        ('modules', ['modules/app.ico']),
        # this modules are automatically added if you use __init__.py in your folder
        # ('modules', ['modules/scraper_module.py']),
        # ('modules', ['modules/gui_module.py']),
    ]

    OPTIONS = {
        'argv_emulation': False,
        'iconfile': 'modules/app.ico',
        'plist': {
            'CFBundleName': APP_NAME,
            'CFBundleDisplayName': APP_NAME,
            'CFBundleGetInfoString': APP_NAME,
            'CFBundleVersion': VERSION,
            'CFBundleShortVersionString': VERSION,
            'PyRuntimeLocations': [
                executable_stub,
                # also the executable can look like this:
                #'@executable_path/../Frameworks/libpython3.4m.dylib',
            ]
        }
    }

def main():
    setup(
        name=CONFIG.APP_NAME,
        app=CONFIG.APP,
        data_files=CONFIG.DATA_FILES,
        options={'py2app': CONFIG.OPTIONS},
        setup_requires=['py2app'],
        maintainer='foo bar',
        author_email='foo@domain.com',
    )

if __name__ == '__main__':
    main()

然后你需要运行python3 Setup.py py2app,现在你可以go ,只需双击your_app_{VERSION}_{platform}.app.

Recomendations by the py2app docs:

  1. 确保不使用-A标志
  2. 当程序使用图形用户界面工具包(如Tkinter)py2app options docs时,不要使用--argv-emulation

Python相关问答推荐

线性模型PanelOLS和statmodels OLS之间的区别

Odoo 14 hr. emergency.public内的二进制字段

追溯(最近最后一次调用):文件C:\Users\Diplom/PycharmProject\Yolo01\Roboflow-4.py,第4行,在模块导入roboflow中

如何过滤包含2个指定子字符串的收件箱列名?

数据抓取失败:寻求帮助

当从Docker的--env-file参数读取Python中的环境变量时,每个\n都会添加一个\'.如何没有额外的?

如何在Python数据框架中加速序列的符号化

如果条件不满足,我如何获得掩码的第一个索引并获得None?

字符串合并语法在哪里记录

如何更新pandas DataFrame上列标题的de值?

在两极中过滤

无论输入分辨率如何,稳定扩散管道始终输出512 * 512张图像

numpy.unique如何消除重复列?

如果有2个或3个,则从pandas列中删除空格

仅使用预先计算的排序获取排序元素

比较两个有条件的数据帧并删除所有不合格的数据帧

分解polars DataFrame列而不重复其他列值

将Pandas DataFrame中的列名的长文本打断/换行为_STRING输出?

在不降低分辨率的情况下绘制一组数据点的最外轮廓

Pandas:根据相邻行之间的差异过滤数据帧