Creating a standalone macOS application with Python and py2app

Question:

I want to create a standalone app which can be used globally on other Macs other than mine.

I followed the tutorial from this page: https://www.metachris.com/2015/11/create-standalone-mac-os-x-applications-with-python-and-py2app/

However after the Building for Deployment step is finished and i want to run the app in the dist folder by double clicking it, i get this error message:

"*MYAPP* has encountered a fatal error, and will not terminate.

A Python runtime not could be located. You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this application's Info.plist file"

–> I assume that I have to install Python in my virtual environment. Moreover, i know that in order to solve this Problem maybe I have to use "Macports". I know this by following and reading this thread and following the problem root: py2app is not copying the Python.framework to the new app while using virutalenv

But even after reading it I don’t understand:

–> How to install Python in my virtual environment in order to create a standalone executable application for macs.

my Python script runs just fine when I execute it in the terminal and I don’t use any packages for this little application, so there shouldn’t be any dependencies from other packages.

Edit: Here is my setup.py file:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['Sandwich.py']
DATA_FILES = []
OPTIONS = {}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Moreover, here is a overview of the direction tree:

├── Sandwich.py
├── build
│   └── bdist.macosx-10.13-intel
│       └── python2.7-standalone
│           └── app
│               ├── Frameworks
│               ├── collect
│               │   ├── Carbon
│               │   │   ├── AE.pyc
│               │   │   ├── Appearance.pyc
│               │   │   ├── AppleEvents.pyc
│               │   │   ├── CarbonEvents.pyc
│               │   │   ├── ControlAccessor.pyc
│               │   │   ├── Controls.pyc
│               │   │   ├── Ctl.pyc
│               │   │   ├── Dialogs.pyc
│               │   │   ├── Dlg.pyc
│               │   │   ├── Dragconst.pyc
│               │   │   ├── Events.pyc
│               │   │   ├── Evt.pyc
│               │   │   ├── File.pyc
│               │   │   ├── Files.pyc
│               │   │   ├── Menu.pyc
│               │   │   ├── Qd.pyc
│               │   │   ├── QuickDraw.pyc
│               │   │   ├── Res.pyc
│               │   │   ├── TextEdit.pyc
│               │   │   ├── Win.pyc
│               │   │   ├── Windows.pyc
│               │   │   └── __init__.pyc
│               │   ├── EasyDialogs.pyc
│               │   ├── Finder
│               │   │   ├── Containers_and_folders.pyc
│               │   │   ├── Enumerations.pyc
│               │   │   ├── Files.pyc
│               │   │   ├── Finder_Basics.pyc
│               │   │   ├── Finder_items.pyc
│               │   │   ├── Legacy_suite.pyc
│               │   │   ├── Standard_Suite.pyc
│               │   │   ├── Type_Definitions.pyc
│               │   │   ├── Window_classes.pyc
│               │   │   └── __init__.pyc
│               │   ├── FixTk.pyc
│               │   ├── StdSuites
│               │   │   ├── AppleScript_Suite.pyc
│               │   │   ├── Macintosh_Connectivity_Clas.pyc
│               │   │   ├── QuickDraw_Graphics_Suite.pyc
│               │   │   ├── QuickDraw_Graphics_Suppleme.pyc
│               │   │   ├── Required_Suite.pyc
│               │   │   ├── Standard_Suite.pyc
│               │   │   ├── Table_Suite.pyc
│               │   │   ├── Text_Suite.pyc
│               │   │   ├── Type_Names_Suite.pyc
│               │   │   └── __init__.pyc
│               │   ├── StringIO.pyc
│               │   ├── Tkconstants.pyc
│               │   ├── Tkinter.pyc
│               │   ├── UserDict.pyc
│               │   ├── _LWPCookieJar.pyc
│               │   ├── _MozillaCookieJar.pyc
│               │   ├── __future__.pyc
│               │   ├── _abcoll.pyc
│               │   ├── _builtinSuites
│               │   │   ├── __init__.pyc
│               │   │   └── builtin_Suite.pyc
│               │   ├── _markerlib
│               │   │   ├── __init__.pyc
│               │   │   └── markers.pyc
│               │   ├── _osx_support.pyc
│               │   ├── _strptime.pyc
│               │   ├── _sysconfigdata.pyc
│               │   ├── _threading_local.pyc
│               │   ├── _weakrefset.pyc
│               │   ├── abc.pyc
│               │   ├── aepack.pyc
│               │   ├── aetools.pyc
│               │   ├── aetypes.pyc
│               │   ├── aifc.pyc
│               │   ├── applesingle.pyc
│               │   ├── ast.pyc
│               │   ├── atexit.pyc
│               │   ├── base64.pyc
│               │   ├── bdb.pyc
│               │   ├── bisect.pyc
│               │   ├── calendar.pyc
│               │   ├── chunk.pyc
│               │   ├── cmd.pyc
│               │   ├── codecs.pyc
│               │   ├── collections.pyc
│               │   ├── contextlib.pyc
│               │   ├── cookielib.pyc
│               │   ├── copy.pyc
│               │   ├── copy_reg.pyc
│               │   ├── ctypes
│               │   │   ├── __init__.pyc
│               │   │   ├── _endian.pyc
│               │   │   ├── macholib
│               │   │   │   ├── README.ctypes
│               │   │   │   ├── __init__.pyc
│               │   │   │   ├── dyld.pyc
│               │   │   │   ├── dylib.pyc
│               │   │   │   ├── fetch_macholib
│               │   │   │   ├── fetch_macholib.bat
│               │   │   │   └── framework.pyc
│               │   │   ├── util.pyc
│               │   │   └── wintypes.pyc
│               │   ├── difflib.pyc
│               │   ├── dis.pyc
│               │   ├── distutils
│               │   │   ├── README
│               │   │   ├── __init__.pyc
│               │   │   ├── debug.pyc
│               │   │   ├── dep_util.pyc
│               │   │   ├── errors.pyc
│               │   │   ├── log.pyc
│               │   │   ├── spawn.pyc
│               │   │   ├── sysconfig.pyc
│               │   │   ├── text_file.pyc
│               │   │   └── util.pyc
│               │   ├── doctest.pyc
│               │   ├── dummy_thread.pyc
│               │   ├── dummy_threading.pyc
│               │   ├── encodings
│               │   │   ├── __init__.pyc
│               │   │   ├── aliases.pyc
│               │   │   ├── ascii.pyc
│               │   │   ├── base64_codec.pyc
│               │   │   ├── big5.pyc
│               │   │   ├── big5hkscs.pyc
│               │   │   ├── bz2_codec.pyc
│               │   │   ├── charmap.pyc
│               │   │   ├── cp037.pyc
│               │   │   ├── cp1006.pyc
│               │   │   ├── cp1026.pyc
│               │   │   ├── cp1140.pyc
│               │   │   ├── cp1250.pyc
│               │   │   ├── cp1251.pyc
│               │   │   ├── cp1252.pyc
│               │   │   ├── cp1253.pyc
│               │   │   ├── cp1254.pyc
│               │   │   ├── cp1255.pyc
│               │   │   ├── cp1256.pyc
│               │   │   ├── cp1257.pyc
│               │   │   ├── cp1258.pyc
│               │   │   ├── cp424.pyc
│               │   │   ├── cp437.pyc
│               │   │   ├── cp500.pyc
│               │   │   ├── cp720.pyc
│               │   │   ├── cp737.pyc
│               │   │   ├── cp775.pyc
│               │   │   ├── cp850.pyc
│               │   │   ├── cp852.pyc
│               │   │   ├── cp855.pyc
│               │   │   ├── cp856.pyc
│               │   │   ├── cp857.pyc
│               │   │   ├── cp858.pyc
│               │   │   ├── cp860.pyc
│               │   │   ├── cp861.pyc
│               │   │   ├── cp862.pyc
│               │   │   ├── cp863.pyc
│               │   │   ├── cp864.pyc
│               │   │   ├── cp865.pyc
│               │   │   ├── cp866.pyc
│               │   │   ├── cp869.pyc
│               │   │   ├── cp874.pyc
│               │   │   ├── cp875.pyc
│               │   │   ├── cp932.pyc
│               │   │   ├── cp949.pyc
│               │   │   ├── cp950.pyc
│               │   │   ├── euc_jis_2004.pyc
│               │   │   ├── euc_jisx0213.pyc
│               │   │   ├── euc_jp.pyc
│               │   │   ├── euc_kr.pyc
│               │   │   ├── gb18030.pyc
│               
├── dist
│   └── Sandwich.app
│       └── Contents
│           ├── Info.plist
│           ├── MacOS
│           │   └── Sandwich
│           ├── PkgInfo
│           └── Resources
├── setup.py
└── venv
    ├── bin
    │   ├── activate
    │   ├── activate.csh
    │   ├── activate.fish
    │   ├── activate.ps1
    │   ├── activate.xsh
    │   ├── activate_this.py
    │   ├── easy_install
    │   ├── easy_install-3.8
    │   ├── easy_install3
    │   ├── pip
    │   ├── pip-3.8
    │   ├── pip3
    │   ├── pip3.8
    │   ├── python -> /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
    │   ├── python3 -> python
    │   ├── python3.8 -> python
    │   ├── wheel
    │   ├── wheel-3.8
    │   └── wheel3
    ├── lib
    │   └── python3.8
    │       └── site-packages
    │           ├── _virtualenv.pth
    │           ├── _virtualenv.py
    │           ├── easy_install.py
    │           ├── pip
    │           │   ├── __init__.py
    │           │   ├── __main__.py
    │           │   ├── _internal
    │           │   │   ├── __init__.py
    │           │   │   ├── build_env.py
    │           │   │   ├── cache.py
    │           │   │   ├── cli
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── autocompletion.py
    │           │   │   │   ├── base_command.py
    │           │   │   │   ├── cmdoptions.py
    │           │   │   │   ├── command_context.py
    │           │   │   │   ├── main.py
    │           │   │   │   ├── main_parser.py
    │           │   │   │   ├── parser.py
    │           │   │   │   ├── req_command.py
    │           │   │   │   └── status_codes.py
    │           │   │   ├── commands
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── check.py
    │           │   │   │   ├── completion.py
    │           │   │   │   ├── configuration.py
    │           │   │   │   ├── debug.py
    │           │   │   │   ├── download.py
    │           │   │   │   ├── freeze.py
    │           │   │   │   ├── hash.py
    │           │   │   │   ├── help.py
    │           │   │   │   ├── install.py
    │           │   │   │   ├── list.py
    │           │   │   │   ├── search.py
    │           │   │   │   ├── show.py
    │           │   │   │   ├── uninstall.py
    │           │   │   │   └── wheel.py
    │           │   │   ├── configuration.py
    │           │   │   ├── distributions
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── base.py
    │           │   │   │   ├── installed.py
    │           │   │   │   ├── sdist.py
    │           │   │   │   └── wheel.py
    │           │   │   ├── exceptions.py
    │           │   │   ├── index
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── collector.py
    │           │   │   │   └── package_finder.py
    │           │   │   ├── legacy_resolve.py
    │           │   │   ├── locations.py
    │           │   │   ├── main.py
    │           │   │   ├── models
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── candidate.py
    │           │   │   │   ├── format_control.py
    │           │   │   │   ├── index.py
    │           │   │   │   ├── link.py
    │           │   │   │   ├── scheme.py
    │           │   │   │   ├── search_scope.py
    │           │   │   │   ├── selection_prefs.py
    │           │   │   │   ├── target_python.py
    │           │   │   │   └── wheel.py
    │           │   │   ├── network
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── auth.py
    │           │   │   │   ├── cache.py
    │           │   │   │   ├── download.py
    │           │   │   │   ├── session.py
    │           │   │   │   ├── utils.py
    │           │   │   │   └── xmlrpc.py
    │           │   │   ├── operations
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── build
    │           │   │   │   │   ├── __init__.py
    │           │   │   │   │   ├── metadata.py
    │           │   │   │   │   ├── metadata_legacy.py
    │           │   │   │   │   ├── wheel.py
    │           │   │   │   │   └── wheel_legacy.py
    │           │   │   │   ├── check.py
    │           │   │   │   ├── freeze.py
    │           │   │   │   ├── install
    │           │   │   │   │   ├── __init__.py
    │           │   │   │   │   ├── editable_legacy.py
    │           │   │   │   │   ├── legacy.py
    │           │   │   │   │   └── wheel.py
    │           │   │   │   └── prepare.py
    │           │   │   ├── pep425tags.py
    │           │   │   ├── pyproject.py
    │           │   │   ├── req
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── constructors.py
    │           │   │   │   ├── req_file.py
    │           │   │   │   ├── req_install.py
    │           │   │   │   ├── req_set.py
    │           │   │   │   ├── req_tracker.py
    │           │   │   │   └── req_uninstall.py
    │           │   │   ├── self_outdated_check.py
    │           │   │   ├── utils
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── appdirs.py
    │           │   │   │   ├── compat.py
    │           │   │   │   ├── deprecation.py
    │           │   │   │   ├── distutils_args.py
    │           │   │   │   ├── encoding.py
    │           │   │   │   ├── entrypoints.py
    │           │   │   │   ├── filesystem.py
    │           │   │   │   ├── filetypes.py
    │           │   │   │   ├── glibc.py
    │           │   │   │   ├── hashes.py
    │           │   │   │   ├── inject_securetransport.py
    │           │   │   │   ├── logging.py
    │           │   │   │   ├── marker_files.py
    │           │   │   │   ├── misc.py
    │           │   │   │   ├── models.py
    │           │   │   │   ├── packaging.py
    │           │   │   │   ├── pkg_resources.py
    │           │   │   │   ├── setuptools_build.py
    │           │   │   │   ├── subprocess.py
    │           │   │   │   ├── temp_dir.py
    │           │   │   │   ├── typing.py
    │           │   │   │   ├── ui.py
    │           │   │   │   ├── unpacking.py
    │           │   │   │   ├── urls.py
    │           │   │   │   ├── virtualenv.py
    │           │   │   │   └── wheel.py
    │           │   │   ├── vcs
    │           │   │   │   ├── __init__.py
    │           │   │   │   ├── bazaar.py
    │           │   │   │   ├── git.py
    │           │   │   │   ├── mercurial.py
    │           │   │   │   ├── subversion.py
    │           │   │   │   └── versioncontrol.py
    │           │   │   └── wheel_builder.py
    │           │   └── _vendor
    │           │       ├── __init__.py
    │           │       ├── appdirs.py
    │           │       ├── cachecontrol
    │           │       │   ├── __init__.py
    │           │       │   ├── _cmd.py
    │           │       │   ├── adapter.py
    │           │       │   ├── cache.py
    │           │       │   ├── caches
    │           │       │   │   ├── __init__.py
    │           │       │   │   ├── file_cache.py
    │           │       │   │   └── redis_cache.py
    │           │       │   ├── compat.py
    │           │       │   ├── controller.py
    │           │       │   ├── filewrapper.py
    │           │       │   ├── heuristics.py
    │           │       │   ├── serialize.py
    │           │       │   └── wrapper.py
    │           │       ├── certifi
    │           │       │   ├── __init__.py
    │           │       │   ├── __main__.py
    │           │       │   ├── cacert.pem
    │           │       │   └── core.py
    │           │       ├── chardet
    │           │       │   ├── __init__.py
    │           │       │   ├── big5freq.py
    │    
    │           │   ├── ssl_support.py
    │           │   ├── unicode_utils.py
    │           │   ├── version.py
    │           │   ├── wheel.py
    │           │   └── windows_support.py
    │           ├── setuptools-46.1.3.dist-info
    │           │   ├── INSTALLER
    │           │   ├── LICENSE
    │           │   ├── METADATA
    │           │   ├── RECORD
    │           │   ├── WHEEL
    │           │   ├── dependency_links.txt
    │           │   ├── entry_points.txt
    │           │   ├── top_level.txt
    │           │   └── zip-safe
    │           ├── setuptools-46.1.3.virtualenv
    │           ├── wheel
    │           │   ├── __init__.py
    │           │   ├── __main__.py
    │           │   ├── _version.py
    │           │   ├── bdist_wheel.py
    │           │   ├── cli
    │           │   │   ├── __init__.py
    │           │   │   ├── convert.py
    │           │   │   ├── install.py
    │           │   │   ├── pack.py
    │           │   │   └── unpack.py
    │           │   ├── macosx_libfile.py
    │           │   ├── metadata.py
    │           │   ├── pep425tags.py
    │           │   ├── pkginfo.py
    │           │   ├── util.py
    │           │   └── wheelfile.py
    │           ├── wheel-0.34.2.dist-info
    │           │   ├── INSTALLER
    │           │   ├── LICENSE.txt
    │           │   ├── METADATA
    │           │   ├── RECORD
    │           │   ├── WHEEL
    │           │   ├── entry_points.txt
    │           │   └── top_level.txt
    │           └── wheel-0.34.2.virtualenv
    └── pyvenv.cfg

–> To be honest I didn’t expect the direction tree to be that complex; I even deleted some files due character limitation on stackoverflow.

Asked By: philuix

||

Answers:

Looks like you’re having an interpreter version mismatch.

Remove your environment, then in your project folder try:

$ python3 -m venv env
$ . env/bin/activate
$ pip install py2app

Then try out https://py2app.readthedocs.io/en/latest/tutorial.html#create-a-setup-py-file

Answered By: OpSocket
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.