我正在使用 Anaconda 发行版中的 Python 3,并尝试将简单的 Python 程序转换为 OS X 应用程序(在 El Capitan 上运行).按照教程中的说明,我跑了
I am using Python 3 from the Anaconda distribution, and trying to convert a simple python program into an OS X app (running on El Capitan). Following the instructions in the tutorial, I ran
py2applet --make-setup my-script.py
python setup.py py2app -A
一切正常,没有错误,但是当我尝试启动应用程序时,我收到以下错误消息:
Everything ran fine with no errors, but when I try to launch the app, I get this error message:
my-script:无法(原文如此)定位 python 运行时.您可能需要安装 Python 的框架构建,或编辑此应用程序 Info.plist 文件中的 PyRuntimeLocations 数组.
my-script: A python runtime not could (sic) be located. You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this applications Info.plist file.
我理解这意味着我应该添加 Anaconda 的 python 的路径(在我的 bash PATH 中,但启动器不知道).但是,应用程序自动生成的 Info.plist
已经指向 Anaconda python 二进制文件:
I understood this to mean I should add the path of Anaconda's python (which is in my bash PATH, but is not known to the launcher). However, the app's automatically generated Info.plist
already points to the Anaconda python binary:
<key>PythonInfoDict</key>
<dict>
<key>PythonExecutable</key>
<string>/Applications/Experimental/anaconda/bin/python</string>
...
我看不出这里有什么需要解决的.我已经阅读了这些相关问题:
I don't see what there is to fix here. I have read these related questions:
第一个问题涉及相同的错误消息,并按照第二个问题中的建议解决.但据我了解,这些问题描述了相反的情况: OP 正在运行与操作系统一起分发的 python,并且想要分发他们的应用程序;解决方案是使用单独安装的python.我 am 使用非系统 python,我还没有尝试分发任何东西.那么是什么造成了这里的麻烦,解决方法是什么?
The first question involves the same error message, and is resolved by following the advice in the second question. But as I understand it, these questions describe the opposite situation: The OP was running a python distributed with the OS, and wanted to distribute their app; the solution is to use a separately installed python. I am using a non-system python, and I'm not yet trying to distribute anything. So what is causing the trouble here, and what is the solution?
@l'L'l 的建议让我发现了问题:虽然我在别名模式"下生成应用时没有错误(使用符号链接到环境而不是复制二进制文件),在没有别名模式的情况下构建应用程序会清除错误:py2app
在不存在的名称 下查找
.libpython
DLL/Applications/anaconda/lib/libpython3.4.dylib
The suggestion by @l'L'l allowed me to identify the problem: While there were no errors when I generated my app in "alias mode" (using symlinks to the environment instead of copying binaries), building the app without alias mode flushed out the error: py2app
looks for the libpython
DLL under the non-existent name /Applications/anaconda/lib/libpython3.4.dylib
.
快速检查显示 Anaconda 以稍微不同的名称提供此 DLL:libpython3.4m.dylib
.虽然修补 dist/my-script.app/Contents/Info.plist
解决了问题,正确的解决方案是编辑 setup.py
所以未来的构建将正常工作.在 py2app 文档 的帮助下,我整理了以下(部分内容setup.py
显示):
A quick check showed that Anaconda provides this DLL under a slightly different name: libpython3.4m.dylib
. While patching dist/my-script.app/Contents/Info.plist
fixes the problem, the right solution is to edit setup.py
so that future builds will work correctly. With the help of the py2app documentation, I put together the following (partial contents of setup.py
shown):
OPTIONS = {'argv_emulation': True,
'plist': {
'PyRuntimeLocations': [
'@executable_path/../Frameworks/libpython3.4m.dylib',
'/Applications/anaconda/lib/libpython3.4m.dylib'
]
}}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
路径来自生成的Info.plist
;我只修改了绝对路径,原因是如果我在相对路径中提供了一个本地 DLL,它将具有默认名称.
The paths come from the generated Info.plist
; I only modified the absolute path, reasoning that if I ever provide a local DLL at the relative path, it will have the default name.
这篇关于如何将 py2app 与 Anaconda python 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!