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)”.
py2app Official website :https://pythonhosted.org/py2app/
Installation command :
pip install py2app
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.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