程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python packaged as executable app (Mac version)

編輯:Python

PyInstaller: Executable file , Can also be applied to Windows( Close test available )
       

Be careful : It was said on the Internet before Python The new version does not support the use of PyInstaller, I personally support , Please rest assured .

        PyInstaller Support at the same time Windows and macOS Software for , It's a little better : stay macOS What is packed on the is UNIX Executable file , stay Windows What is packed on the is exe file .

        Again , Let's install :

#Python 2:
pip install pyinstaller
 
#Python 3:
pip3 install pyinstaller
        then cd Go to your script Directory , pack :

# take xxx.py Change to your script name
pyinstaller -F xxx.py

        After packing , You will see “xxx.spec” file 、“__pycache__” Folder 、“build” Folders and “dist” Folder . Your executable is also in dist Directory .

        The above is what I bring to you “Python Convert scripts to executables (macOS)”.

Use py2app pack

1. install py2app

py2app Official website :https://pythonhosted.org/py2app/

Installation command :
pip install py2app

2. Prepare one python GUI Program

2.1 First install a gui frame wxpython
Reference resources :
http://wiki.wxpython.org/
http://wiki.wxpython.org/Getting%20Started

2.2 Write code
# !/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. pack

3.1 cd To the current directory to be packaged
cd /Users/xiaoru/Desktop/Learning/PyToApp

3.2 Generate setup file :
py2applet --make-setup hello.py

3.3 Enter packaging command :
python setup.py py2app -A

You can see in the dist Generated in directory app file , Double click to run .


notes : I'm using python3 So all the commands used in the whole process are python Change to python3


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved