PyGUI is the simplest and most lightweight of all GUIs because it is purely in sync with Python programming language. It is a cross-platform graphical application framework for Windows, Mac OS, and Unix. A PyGUI developer inserts very less code between the GUI platform and Python application which in turn displays the natural GUI of the platform. There are a couple options when we think about common installation patterns for applications on macOS. Use Python 3 as the macOS default. Python's website has a macOS Python 3 installer we can download and use. If we use the package installation, a python3 fill will be available in /usr/local/bin/. The “Build Applet” tool that is placed in the MacPython 3.3 folder is fine for packaging small Python scripts on your own machine to run as a standard Mac application. This tool, however, is not robust enough to distribute Python applications to other users. The standard tool for deploying standalone Python applications on the Mac is py2app.
Python for Mac OS X
- PyInstaller freezes Python applications into a stand-alone executables under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX. The user can run and execute the resulting packaged application without installing a Python interpreter or any modules.
- Py2app - Create standalone Mac OS X applications with Python ¶ py2app is a Python setuptools command which will allow you to make standalone application bundles and plugins from Python scripts. Py2app is similar in purpose and design to py2exe for Windows.
Python comes pre-installed on Mac OS X so it is easy to startusing. However, to take advantage of the latest versions ofPython, you will need to download and install newer versionsalongside the system ones. The easiest way to do that is toinstall one of the binary installers for OS X from thePython Download page. Best room layout app for mac. Installers areavailable for the latest Python 3 and Python 2 releases thatwill work on all Macs that run Mac OS X 10.5 and later.
Python releases include IDLE, Python's built-in interactivedevelopment environment. If you download and install Pythonfrom the release page, you may also need to download and installa newer version of Tcl/Tk for OS X. See theIDLE and Tkinter on OS X page formore information.
You can run a Python interpreter by double-clicking onApplications / Utilities / Terminal and typing python3 (if you'veinstalled a version of Python 3) or python (to use Python 2) inthe window that opens up. You can also launch IDLE for the Pythonversion you have installed by double-clicking its icon inthe appropriate Python version folder in the Applications folderor you can also just type idle3 or idle in a terminal window.
There are many thousands of additional Python software packagesavailable through PyPI, the PythonPackage Index. We recommend you use thepip tool to simplifyinstalling and managing additional packages. pip is includedwith Python 3.4 releases; for earlier releases, follow the pipinstall instructions.
Among the packages available through PyPI are some that arespecifically for OS X environments. Among these are:
- pyobjc which providesa bridge between Python and Objective-C, allowing you to writefull-featured native Cocoa applications in pure Python.
- py2app which allowsyou to make standalone OS X double-clickable application bundlesand plugins from Python scripts.
For more information about Python on OS X, see the mailing list and archivesfor thePython-Macintosh Special Interest Group.
Alternative Packages for Mac OS X.
- ActiveState ActivePython(commercial and community versions, including scientific computing modules).
- Enthought Python DistributionThe Enthought Python Distribution provides scientists with a comprehensive setof tools to perform rigorous data analysis and visualization.
Python and a comprehensive set of third-party packages and libraries are alsoavailable from several open source package manager projects for OS X,including:
PyInstaller is a program used to convert Python scripts into standalone applications. PyInstaller allows you to run applications written in Python on a computer without requiring the user to install Python. It is an excellent option when you need to distribute a program to the end user as a standalone application. PyInstaller currently only works with Python 2.3 up to 2.7.
PyInstaller claims to be compatible with a lot of third party libraries or packages out of the box. PyQt, Django and matplotlib are fully supported.
Mac disable downloading app. To start, download and extract PyInstaller from the official site.
PyInstaller is an application, not a package. So there is no need to install it in your computer. To get started, open a Command Prompt (Windows) or a Terminal (Mac and Linux) and go to the PyInstaller Folder. What app to connect canon m50 to mac.
Now suppose you want to package myscript.py, I saved it into the pyinstaller folder:
2
|
print('Hello World!')
|
Then, in order to create the executable just run
python pyinstaller.py myscript.py
and you will see a lot of output and a folder called myscript
will be created, with two folders and a file inside. The build
folder is used by PyInstaller as a temporary folder to create the files needed for the executable. The dist
folder stores the executable and all of the files needed in order to run that executable. It is safe to delete the build folder. The file called myscript.spec
is useful to customize the way PyInstaller packs your application.
Now test if your executable works:
2
|
myscript
|
Python Standalone App
2
|
./myscript
|
You should see now a 'Hello World!' printed on the screen.
Remember that running
python pyinstaller.py myscript.py
assumes that you have Python in your path environment variable. If that is not the case, just use C:Python27python.exe pyinstaller.py myscript.py
in Windows. Most of the time on Linux and Mac OS X, Python will be in your path environment variable.
GUI Applications
Now it is time to create a GUI application. In this example we will be using Tkinter:
2
4
6
8
|
''A very basic Tkinter example. ''
fromTkinterimport*
root.title('A Tk Application')
root.mainloop()
|
To pack it, it is mandatory to use the
--windowed
flag, otherwise the application will not start:
Python For Mac
In this moment you can navigate to the dist folder and run the application by double clicking it.
Note for Mac OS X users: the above example using Tkinter works fine if you use the pre-installed Python version, if you installed or updated Python by yourself, you can find some problems running the packaged application.
Using External Modules
The previous examples were importing modules from the Python Standard Library. PyInstaller includes the Standard Library Modules by default. However if we installed a third party library, PyInstaller is likely not to include it. In most of the cases we need to create 'hooks' to tell PyInstaller to include these modules. An example of this is an application using the ReportLab library to make PDF files:
2
4
6
8
10
12
14
16
18
|
fromreportlab.pdfgen importcanvas
fromreportlab.lib.units importmm
if__name__'__main__':
city='Pereira'
phone='555-7241'
c=canvas.Canvas(filename='invoice.pdf',pagesize=(letter[0],letter[1]/2))
# Print Customer Data
c.drawString(107*mm,111*mm,city)
c.drawString(107*mm,101*mm,phone)
c.save()
|
![Download python for mac Download python for mac](/uploads/1/3/4/0/134069252/987079457.jpg)
A 'hook' module is a Python file with a special name, used to tell PyInstaller to include a specific module. Doing a Google search i found the needed hooks to pack a ReportLab application here and placed them in a folder named 'hooks':
+- hooks/
|- hook-reportlab.pdfbase._fontdata.py
|- hook-reportlab.pdfbase.py
|- hook-reportlab.py
|- hook-reportlab.pdfbase._fontdata.py
|- hook-reportlab.pdfbase.py
|- hook-reportlab.py
hook-reportlab.py
and hook-reportlab.pdfbase.py
are empty files, hook-reportlab.pdfbase._fontdata.py
contains:
2
4
6
8
10
12
14
16
18
20
22
24
|
hiddenimports=[
'_fontdata_enc_macroman',
'_fontdata_enc_standard',
'_fontdata_enc_winansi',
'_fontdata_widths_courier',
'_fontdata_widths_courierboldoblique',
'_fontdata_widths_helvetica',
'_fontdata_widths_helveticaboldoblique',
'_fontdata_widths_symbol',
'_fontdata_widths_timesbolditalic',
'_fontdata_widths_timesroman',
]
|
Now in order to pack the executable, we have to run
python pyinstaller.py --additional-hooks-dir=hooks/ invoice.py
. The additional-hooks-dir
flag tells PyInstaller to search for hooks in the specified directory.
Conclusion
Pyinstaller works great if your script only imports modules from The Python Standard Library, or a module included in the official Supported Packages list. Using these supported packages make packaging applications pretty straightforward, but when wee need to use a third-party not supported module, it can be tricky to make it work.