python打包成可执行文件app(Mac版) 您所在的位置:网站首页 mac可执行程序 python打包成可执行文件app(Mac版)

python打包成可执行文件app(Mac版)

2023-08-19 12:44| 来源: 网络整理| 查看: 265

PyInstaller:可执行文件,也适用于Windows(亲测可用)        

注意:之前网上有说Python新版本不支持使用PyInstaller,本人亲测是支持的,请大家放心。

        PyInstaller是同时支持Windows和macOS的软件,它有一点比较好:在macOS上打包的便是UNIX可执行文件,在Windows上打包的便是exe文件。

        同样,我们先安装:

#Python 2: pip install pyinstaller   #Python 3: pip3 install pyinstaller         然后cd到你脚本的目录下,打包:

#将xxx.py改为你的脚本名称 pyinstaller -F xxx.py         打包完成之后,你将会看到“xxx.spec”文件、“__pycache__”文件夹、“build”文件夹以及“dist”文件夹。你的可执行文件同样在dist目录里。

        以上就是我为大家带来的“Python将脚本转换为可执行文件(macOS)”。

使用py2app打包 1. 安装py2app

py2app官网:https://pythonhosted.org/py2app/

安装命令:pip install py2app

2. 准备一个python GUI 程序

2.1 首先安装一个gui框架 wxpython 参考: http://wiki.wxpython.org/ http://wiki.wxpython.org/Getting%20Started

2.2 写代码 # !/usr/bin/env python

import wx

app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window. frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window. frame.Show(True) # Show the frame. app.MainLoop()

3. 打包

3.1 cd到要打包的当前目录下 cd /Users/xiaoru/Desktop/Learning/PyToApp

3.2 生成setup文件:py2applet --make-setup hello.py

3.3 输入打包命令:python setup.py py2app -A

可以看到在dist目录下生成了app文件, 双击可以运行了。

注:我使用的是python3 所以全程用到的命令都是把python改成python3



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有