如何将py2app与Anaconda python一起使用? [英] How do I use py2app with Anaconda python?

查看:279
本文介绍了如何将py2app与Anaconda python一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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:

我的脚本:找不到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:

  • How do I use py2app with a virtual environment?
  • py2app is not copying the python framework to the new app while using virutalenv

第一个问题涉及相同的错误消息,并且可以通过遵循第二个问题中的建议来解决.但是据我所知,这些问题描述了相反的情况:OP运行与OS一起分发的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在不存在的名称/Applications/anaconda/lib/libpython3.4.dylib下查找libpython DLL.

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可以解决问题时, right 解决方案是编辑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一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆