Python For Mac App



PyInstaller freezes (packages) Python applications into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX. If you have problems to get your application running, please have a look at If Things Go Wrong and How to Report Bugs, which will help us a. You can interactively create an app project with Run Shell Script action, then paste in your script in its editor, select your shell program (/usr/bin/python), finally save the project. And you have yourself a Mac native app. Automator can also be driven by AppleScript. So you can pipeline this py-2-app conversion process to your build scripts. Visual Studio IDE Visual Studio for Mac Visual Studio Code. To continue downloading, click here. Python Tools for Visual Studio 2020-08-28T11:00:15-07:00. Visual Studio Technologies. Develop Python applications. Python; Full Installer; Python; Python. Editing, debugging, interactive development for Python apps, using familiar frameworks. Azure Pipelines for Python Run CI/CD for your Python apps, with support for Linux, macOS and Windows. Free for individuals, small teams, and open source projects.

This page tells you how to setup a Python programming environment for your Mac OS X computer and provides a step-by-step guide for creating and running a simple 'Hello, world' Python program. All of the software is freely available on the Web. These instructions are for MacOS X 10.13 (High Sierra), but the instructions for other recent versions of Mac OS X are similar.


Overview

The Python programming environment required by this booksite consists of:

  • Python, that is, the Python compiler/interpreter.
  • The Python standard libraries.
  • IDLE, the Python Integrated DeveLopment Environment.
  • The Tkinter, NumPy, and Pygame libraries, which are used by the booksite programs that do graphics or audio processing.
  • The booksite library, that is, a set of modules that we developed specifically to support this booksite.
  • The Terminal application that is bundled with Mac OS X.

Downloading and Installing Python, IDLE, Tkinter, NumPy, and Pygame

Note: The Mac Finder application uses the term folder to mean a container of documents and, perhaps, other folders. This document instead uses the equivalent Unix term directory.

Python 2 is bundled with Mac OS X. However, Python 3 is not. We recommend that you download and install Python 3, and use Python 3 exclusively when running programs associated with this booksite.

Perform these steps to download and install Python, IDLE, Tkinter, NumPy, and PyGame:

  • Browse to the Python for Mac download page.

  • In the resulting page click on the Download Python 3.6.5 button. Your browser will download the file python-3.6.5-macosx10.6.pkg to your Downloads directory.

  • Using Mac Finder Manager, navigate to your Downloads directory, and double-click on the python-3.6.5-macosx10.6.pkg file to install Python, Tkinter, and IDLE. Use the default options. (It's OK to delete the python-3.6.5-macosx10.6.pkg file after the installation is complete.)

  • Open a Terminal window. To do that, click on the Spotlight Search icon on the right end of the menu bar. (It has the appearance of a magnifying glass.) In the resulting dialog box, type Terminal.app followed by the Enter key.

  • In the Terminal window issue these commands to install NumPy and PyGame:

To 'issue a command' you should type the command followed by the Enter key.

Perform these steps to test your installation:

  • In the Terminal window issue the python3 command. You should see something like this:

  • If you see that output, then your installation of Python, IDLE, and Tkinter was successful.

  • At the Python >>> prompt, type import numpy followed by the Enter key. If no error messages appear, then your installation of NumPy was successful.

  • At the Python >>> prompt, type import pygame followed by the Enter key. If no error messages appear, then your installation of PyGame was successful.

  • At the Python >>> prompt, type exit() followed by the Enter key to exit Python.

  • In the Terminal window issue the command idle3. If an IDLE window appears, then you have installed IDLE properly. Close the IDLE window.
  • Close the Command Prompt window.

IMPORTANT: When running the Python programs associated with this booksite, do not issue the python command. Instead issue the python3 command. The former command runs the Python 2 compiler/interpreter that is bundled with Mac OS X; the latter command runs the Python 3 compiler/interpreter that you installed by following the instructons on this page.

Downloading and Installing the Booksite Library

Perform these steps to download and install the booksite library:

Py to app
  • Use your Web browser to download this introcs-1.0.zip file to your /Users/yourusername/Downloads directory.

  • In the Finder, double click on /Users/yourusername/Downloads/introcs-1.0.zip to unzip the file, thus creating a directory named /Users/yourusername/Downloads/introcs-1.0. (It's OK to delete the /Users/yourusername/Downloads/introcs-1.0.zip file after you have unzipped it.)

  • Open a Terminal window.

  • At any time the Terminal application has a working directory. Initially the working directory is /Users/yourusername. In the Terminal window issue the cd Downloads command to change your working directory to /Users/yourusername/Downloads, and then issue the cd introcs-1.0 command to change your working directory to /Users/yourusername/Downloads/introcs-1.0. (Incidentally, the cd .. command changes your working directory to the 'parent' of the current working directory.)

  • Issue the ls command to display the names of all files in your working directory. Make sure that a file named setup.py is in your working directory.

  • Issue the python3 setup.py install --user command. The computer copies the files defining the booksite modules to a directory where Python can find them, and writes status messages to your Terminal window to indicate its progress.

Perform these steps to test your installation of the booksite library:

  • In the Terminal window issue the python3 command.

  • At the Python >>> prompt, type the statement import stdio followed by the Enter key. If Python generates no error messages, then you have installed the booksite library properly.

  • At the Python >>> prompt, type exit() followed by the Enter key to exit Python.

  • Close the Terminal window.


Configuring IDLE

Python mac app store

So far you've downloaded and installed all of the software that you'll need. You should perform one more step before creating your first program: configure the IDLE programming environment. Follow these instructions:

Python Native Mac App

  • Open a Terminal window.

  • In the Terminal window issue the command idle3 to launch IDLE.

  • Click on the Python → Preferences... menu item.

  • Click on the General tab.

  • Click on the Open Edit Window radio button.

  • Click on the Ok button.

  • Close the IDLE window.

  • Close the Terminal window.


Composing Your First Program

Having installed Python, the Python standard libraries, IDLE, Tkinter, NumPy, Pygame, and the booksite libraries, and having configured IDLE, you are ready to compose your first Python program. Perform these instructions:

  • Using the Mac Finder, create a directory named /Users/yourusername/hello.

  • Open a Terminal window.

  • Issue the cd hello command to make the /Users/yourusername/hello directory your working directory.

  • Issue the command idle3 & to launch IDLE. Note the trailing ampersand. The trailing ampersand tells the computer to run the idle3 program in the background, thereby leaving your Terminal application free to handle additional commands while IDLE is running.

  • In IDLE, type the four-line Python program helloworld.py exactly as it appears below. Use the arrow keys, mouse, or touchpad to move within the text that you have typed. Use the Delete key to delete text. Be careful; the smallest typing mistake might cause the program to fail.

  • When you are finished typing, in IDLE click on the File → Save... menu item to save the Python program. Save it in a file named helloworld.py in the directory /Users/yourusername/hello. The file name is case sensitive, so make sure you use all lowercase letters.


Running Your First Program

The final step is to run your program. It is possible to run some Python programs from within IDLE, but you should run the programs associated with this booksite directly from a Terminal window. To do that, perform these steps:

  • Within the same Terminal window, issue the ls command to display the names of all files in the working directory. Confirm that the working directory contains your helloworld.py file.

  • Issue the python3 helloworld.py command to run your program. If the computer writes 'Hello, World' to the Terminal window, then the execution of your helloworld.py program was successful. If the computer instead writes error messages, then use IDLE to correct your program, and issue the python3 helloworld.py command again. Repeat until your program runs successfully. If your program runs successfully the first time you try, then intentionally introduce an error into your program, just so you get some experience with correcting errors.

  • Close the IDLE window.

  • Close the Terminal window.

You now have installed and configured a reasonable Python environment, and have used it to compose and run a Python program. Congratulations! You are a Python programmer!


Downloading the Booksite Example Programs (optional)

We recommend that you download the booksite example programs, that is, the example Python programs that are presented incrementally throughout the booksite. Having done so, you can run those programs to help you learn about them. Perform these instructions:

  • Use your Web browser to download this introcs-python.zip file to your /Users/yourusername/Downloads directory.

  • In the Mac Finder, double-click on /Users/yourusername/Downloads/introcs-python.zip to unzip the file, thus creating the /Users/yourusername/Downloads/introcs-python directory containing the booksite example programs. (It's OK to delete the /Users/yourusername/Downloads/introcs-python.zip file after you have unzipped it.)

Then perform these steps to test your download of the booksite example programs:

  • Open a Terminal window.

  • Issue the cd Downloads and cd introcs-python commands to make /Users/yourusername/Downloads/introcs-python your working directory.

  • Issue the ls command. Confirm that the working directory contains a file named bouncingball.py.

  • Issue the python3 bouncingball.py command. If Python launches a stddraw window showing an animated bouncing ball, then your download of the booksite example programs was successful.

  • Close the stddraw window.

  • Close the Terminal window.


Downloading the Booksite Example Data (optional)

We recommend that you download the booksite example data, that is, the data files used by the booksite example programs that are presented incrementally throughout the booksite. Perform these instructions:

  • Use your Web browser to download this introcs-data.zip file to your /Users/yourusername/Downloads directory.

  • In the Finder, double-click on /Users/yourusername/Downloads/introcs-data.zip to unzip the file, thus creating the /Users/yourusername/Downloads/introcs-data directory containing the booksite example data files. (It's OK to delete the /Users/yourusername/Downloads/introcs-data.zip file after you have unzipped it.)


Downloading the Booksite Library: Part 2 (optional)

Previously on this page we described how to download and install the booksite library so Python can find it. Now we describe how to download the booksite library so you can find it — for the sake of studying the code that implements it, should you so desire. Perform these instructions:

  • Use your Web browser to download this stdlib-python.zip file to your /Users/yourusername/Downloads directory.

  • In the Mac Finder, double-click on /Users/yourusername/Downloads/stdlib-python.zip to unzip the file, thus creating the /Users/yourusername/Downloads/stdlib-python directory containing the booksite library. (It's OK to delete the /Users/yourusername/Downloads/stdlib-python.zip file after you have unzipped it.)

We invite you to study the code that implements the booksite library. But don't be concerned if some of the code is cryptic. The code that implements the booksite library uses some features of Python that are beyond the scope of the textbook and this booksite.


Q & A

Q. Why do I get the error ImportError: No module named stdio when I issue the command python program_that_uses_stdio.py?

A. You must issue the command python3 program_that_uses_stdio.py, as described above.

Q. I downloaded files using my browser, but can't find them. Where are they?

A. Many browsers by default place downloaded files in the directory /Users/yourusername/Downloads.

Q. How do I break out of an infinite loop when running my program from the Terminal application?

A. Type Ctrl-c. That is, while pressing the Ctrl key, type the c key.

Q. Must I use IDLE to create my Python programs? Can I use some other text editor?

A. You need not use IDLE to create your Python programs; it is fine to use some other text editor. For example, it is reasonable to use the TextEdit editor that is bundled with Mac OS X. However if you do use some other text editor, then make sure you change its settings so it (1) uses a four-space indentation scheme, and (2) indents using spaces instead of tabs. The Wikipedia Comparison of text editors page provides summary descriptions of many text editors.

Recently I needed to submit a Python app to the Mac App Store. Since there seemed to be no good documentation online for doing this, I had to figure it out myself. Here’s what I learned:

Building a Python app for the Mac App Store

Below I will explain how to make a Python script into a Mac App Store app. I would recommend that you download my example Python app that can be submitted to the Mac App Store and examine its build system while reading the rest of this article.

Get a Python script

First, I assume you already have a Python script that you’d like to package as an application and submit.

My example app uses src/HelloAppStore.py as the main script.

Make it into a regular app

A Python script, along with its included Python modules and dependencies, can be bundled into a regular Mac app using py2app.

I won’t repeat the py2app documentation, but you generally need to create a setup.py file that looks something like this:

Appium

Then you can build dist/HelloAppStore.app into a nice double-clickable app by running the command:

My example app runs the above command as part of the ./build-app.sh script.

Alter the app to conform to Mac App Store constraints

There are several additional nontrivial restrictions that must be satisfied before an app can be submitted to the Mac App Store:

  • It must be able to run in sandboxed mode.
  • It must be code-signed.
  • It must not depend on any deprecated APIs (like QuickTime), even from included libraries.
  • It must not include any PowerPC code, even from included libraries.
  • It must have a large app icon (with sizes up to 1024x1024).
  • It must have a specified app store category.
  • It must not have any content that Apple finds offensive in its sole discretion.

An exhaustive list of restrictions can be found in the Mac App Store Review Guidelines.

Sandboxing

Mac App Store apps must be sandboxed. Sandboxed apps are restricted in several ways, but the most significant restriction is the inability to read/write arbitrary files.

In particular an app cannot write to a file outside of its sandbox container unless a native1 open/save dialog is used to prompt for the location of the file or the file already resides within the app’s container directory.

It’s a good idea to read the App Sandboxing documentation to understand the full set of restrictions and how to overcome them when necessary (and when possible).

My example app enables sandboxing by specifying that com.apple.security.app-sandbox = true in the src/app.entitlements file. This entitlements file is used in the code-signing process described in the next section.

Code-signing

Mac App Store apps must be code-signed. This means you must go through some extra hoops to generate signing certificates, download them to your dev machine, and alter your build script to sign the final app package with it.

These certificates have to be generated by Apple as part of your Mac Developer Program subscription ($99/year). And renewed annually if you wish to continue making app updates.

Since Python apps are built outside of Xcode, you’ll have to use the codesign tool manually to sign your app.

My example app runs the codesign tool as part of the ./build-app.sh script, recursively signing the inner frameworks, helper tools, and finally the outer application binaries. As part of the signing process the application binaries are also embedded with entitlements, which are used to enable sandboxing.

See the Code Signing Guide for more information about manual code-signing.

Deprecated APIs

Your Python script probably won’t be directly using any deprecated APIs. However your Python script might depend on other libraries that do. Such dependencies can be difficult or impossible to eliminate. Typically you have to modify and recompile the dependency manually.

Python Open Mac App

In particular the very popular wxPython GUI toolkit depends on deprecated QuickTime APIs at the time of writing, making any Python app that depends on it inadmissible to be submitted to the Mac App Store.

My example app has no workarounds for deprecated APIs.

PowerPC Code

Your Python script probably won’t be directly using any old PowerPC code. However, again, your Python script might depend on other libraries that do. In fact Python 2.7 itself includes PowerPC code.

Luckily any PowerPC code can be stripped out easily using the lipo tool, so you just need to add some extra lipo commands to your build script.

My example app uses lipo in the ./build-app.sh script to remove PowerPC code from the python2.7 library.

Large App Icon

If you don’t have an app icon you’ll have to create one. If you do already have an app icon, I’ll bet you it doesn’t meet the minimum 1024x1024 pixel size requirement.

Creating an icon entails creating several images for your icon at various specific sizes, and then using the iconutil command to generate a final .icns icon file.

My example app contains a ./build-icon.sh script that can be used to generate src/Icon.icns from images in the src/Icon.iconset directory.

See the Icon Design Guidelines in the OS X Human Interface Guidelines for more information about creating icons.

App Store Category

The Info.plist file inside a Mac App Store app is required to specify what category on the Mac App Store it belongs to under the LSApplicationCategoryType key.

So far as I can tell, the set of valid values for this key is not documented anywhere. Therefore to find new values, I created a new Cocoa Application project in Xcode (where I could specify the app category in a dropdown), compiled the app, and opened its Info.plist file to see what value it had for the LSApplicationCategoryType key.

Python For Mac AppPython For Mac App

Submitting your app to the store

Regular apps written in Objective-C for the Mac App Store are usually submitted directly from within Xcode. This is not an option for Python apps that you build outside of Xcode.

Instead you have to use an older app submission tool called Application Loader to upload your app. However Application Loader doesn’t submit a .app package directly; it requires an installer .pkg instead.

An installer package can be built from your .app using the productbuild tool.

My example app runs the productbuild tool as part of the ./build-pkg.sh script which creates an installer package containing the app.

For more information about the productbuild tool, see its man page.

Fin

Download Python For Mac

Hopefully you should now have a good idea of what is involved in submitting a Python app to the Mac App Store.

Python Appium Mac

If you’d like to actually try out the process of submitting an app, try building and submitting my example app using the instructions in its README.

Please send comments and corrections to David Foster.

Python For Mac App Free

  1. Therefore if you are using a GUI toolkit that uses a simulated open/save dialog rather than a native one, your app won’t be able to access the files the user selects!↩