py2app 打包

1 .安装与使用

1.1 安装

pip3 install py2app

1.2. 创建一个setup.py文件

py2applet --make-setup MyApplication.py

1.3. 创建部署

python3 setup.py py2app

1.4. 清理你的build目录

rm -rf build dist

2 .图标

如果您的应用程序具有所需的图标(.icns格式)或数据文件,则还应将它们指定为py2applet的参数。

  1. png转生成以下png图片
    sips -z 16 16 icon.png --out pngpic.iconset/icon_16x16.png
  2. 执行命令iconutil -c icns pngpic.iconset -o txt.icns,生成icns图片

2.2 .修改setup.py设置

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['ttk_demo.py']
DATA_FILES = [
    'icon.png'
]
OPTIONS = {
    'argv_emulation':True,
    'iconfile':'/Users/lg/Desktop/demo/python_test/tkinter_demo/icon.icns'
}

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

3. 跨平台

跨平台应用程序可以共享py2exe和py2app 的setup.py脚本 。这是一个自我引导示例,它将在Windows或Mac OS X上构建应用程序: setup.py

"""
 py2app/py2exe build script for MyApplication.

 Will automatically ensure that all build prerequisites are available
 via ez_setup

 Usage (Mac OS X):
     python setup.py py2app

 Usage (Windows):
     python setup.py py2exe
 """
 import ez_setup
 ez_setup.use_setuptools()

 import sys
 from setuptools import setup

 mainscript = 'MyApplication.py'

 if sys.platform == 'darwin':
     extra_options = dict(
         setup_requires=['py2app'],
         app=[mainscript],
         # Cross-platform applications generally expect sys.argv to
         # be used for opening files.
         options=dict(py2app=dict(argv_emulation=True)),
     )
 elif sys.platform == 'win32':
     extra_options = dict(
         setup_requires=['py2exe'],
         app=[mainscript],
     )
else:
     extra_options = dict(
         # Normally unix-like platforms will use "setup.py install"
         # and install the main script as such
         scripts=[mainscript],
     )

setup(
    name="MyApplication",
    **extra_options
)

你可能感兴趣的:(py2app 打包)