如何为 MacOs Big Sur 使用 pyinstaller?

How to use pyinstaller for MacOs Big Sur?

我有一个小工具。 这些是外部库。

import pyperclip
import webbrowser
import tkinter as tk

如何使用 pyinstaller 使其成为 macOs 桌面应用程序?This is the code.

只需执行:

pyinstaller --windowed <script name>.py

这将创建一个包含可执行文件的 dist 文件夹,您可以将其发送给您的用户。

More info on PyInstaller Docs

按照本指南在 MacOS 上安装 pyinstaller。

https://pyinstaller.readthedocs.io/en/stable/requirements.html#mac-os-x

安装后,确保使用pyinstaller --onefile pythonScriptName.py将其创建为单个文件,否则您将有内部包依赖性,这将很难调试。

该应用程序正在安装在一个奇怪的地方。如果你设置一个虚拟环境并在那里安装它就可以成功。

除非你是 运行 大苏尔。然后你会失败,因为 Apple 隐藏了一些动态链接库并且现在没有好的解决方法......

PyInstaller 目前在 Big Sur 上存在问题,原因如下:

New in macOS Big Sur 11.0.1, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286)

执行 pyinstaller 时会丢失系统库

有人在讨论here,但是bug还没有修复。 (2020 年 12 月 21 日)

正如pyinstaller document建议的那样,你最好使用旧版本的OSX 向前兼容。

简单运行:

pyinstaller --windowed my_code.py

我通过再次 brew install pyinstaller 解决了问题