简体   繁体   English

使用 Python 和 py2app 创建独立的 macOS 应用程序

[英]Creating a standalone macOS application with Python and py2app

I want to create an standalone app which can be used globally on other Macs other than mine.我想创建一个独立的应用程序,它可以在我以外的其他 Mac 上全局使用。

I followed the tutorial from this page: https://www.metachris.com/2015/11/create-standalone-mac-os-x-applications-with-python-and-py2app/我按照此页面上的教程进行操作: 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:但是,在构建部署步骤完成后,我想通过双击运行 dist 文件夹中的应用程序,我收到以下错误消息:

"*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. --> 我假设我必须在我的虚拟环境中安装 Python。 Moreover, i know that in order to solve this Problem maybe I have to use "Macports".此外,我知道为了解决这个问题,也许我必须使用“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我通过关注并阅读此线程并关注问题根源知道这一点: py2app is not copy 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. --> 如何在我的虚拟环境中安装 Python 以便为 Mac 创建一个独立的可执行应用程序。

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.我的 Python 脚本在终端中执行时运行良好,并且我不为这个小应用程序使用任何包,因此不应该与其他包有任何依赖关系。

Hopefully someone can help.希望有人可以提供帮助。

Thanks!谢谢!

---Edit--- Here is my setup.py file: ---编辑--- 这是我的 setup.py 文件:

"""
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..由于stackoverflow的字符限制,我什至删除了一些文件。

>>>EDIT - Solution was found<<< >>>编辑 - 找到解决方案<<<

--> The error was due to an interpreter mismatch. --> 错误是由于解释器不匹配造成的。 The only thing i had to change was:我唯一需要改变的是:

Instead of typing in terminal而不是在终端中输入

$ *cd TODIRECTORY*
$ virtualenv venv
$ . venv/bin/activate
$ (...) 

I had to type我不得不打字

$ *cd TODIRECTORY*
$ python3 -m venv env
$ . venv/bin/activate
$ (...) 

--> Hopefully it helps someone! --> 希望它对某人有所帮助!

Thanks to the community for helping to solve this!感谢社区帮助解决这个问题!

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然后尝试https://py2app.readthedocs.io/en/latest/tutorial.html#create-a-setup-py-file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM