Y4R*_*D13 5 python macos tkinter pyinstaller py2app
我正在尝试将 Tkinter 应用程序编译为 MacO 的可执行文件。我尝试使用py2app和pyinstaller。我几乎成功使用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.
Run Code Online (Sandbox Code Playgroud)
看起来是这样的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'],
)
Run Code Online (Sandbox Code Playgroud)
这是目录结构:
-modules/---__init.py__
| |
| -- gui_module.py
| |
| -- scraper_module.py
| |
| -- app.ico
|
-config.json
|
-countries_list.txt
|
-main.py
|
-requirements.txt
|
-setup.py
Run Code Online (Sandbox Code Playgroud)
如果您需要的话,我很乐意分享更多详细信息和文件。
问题是您需要为 MacO 上的 python 框架提供可执行路径。所以我修改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()
Run Code Online (Sandbox Code Playgroud)
然后您需要运行python3 setup.py py2app,现在您只需双击即可your_app_{VERSION}_{platform}.app。
py2app:--argv-emulation当程序使用 GUI 工具包(如 Tkinter)时不要使用py2app 选项文档| 归档时间: |
|
| 查看次数: |
1215 次 |
| 最近记录: |