How do I use py2app with Anaconda python?
<p>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 <a href="https://pythonhosted.org/py2app/tutorial.html" rel="nofollow">the tutorial</a>, I ran </p>

<pre><code>py2applet --make-setup my-script.py
python setup.py py2app -A
</code></pre>

<p>Everything ran fine with no errors, but when I try to launch the app, I get this error message:</p>

<blockquote>
  <p>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. </p>
</blockquote>

<p>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 <code>Info.plist</code> already points to the Anaconda python binary:</p>



<pre><code>&lt;key&gt;PythonInfoDict&lt;/key&gt;
&lt;dict&gt;
    &lt;key&gt;PythonExecutable&lt;/key&gt;
    &lt;string&gt;/Applications/Experimental/anaconda/bin/python&lt;/string&gt;
    ...
</code></pre>

<p>I don't see what there is to fix here. I have read these related questions: </p>

<ul>
<li><a href="http://stackoverflow.com/q/26081258/699305">How do I use py2app with a virtual environment?</a></li>
<li><a href="http://stackoverflow.com/questions/10184974/py2app-is-not-copying-the-python-framework-to-the-new-app-while-using-virutalenv">py2app is not copying the python framework to the new app while using virutalenv</a></li>
</ul>

<p>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 <em>am</em> 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?</p>

<p>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: <code>py2app</code> looks for the <code>libpython</code> DLL under the non-existent name <code>/Applications/anaconda/lib/libpython3.4.dylib</code>. </p>

<p>A quick check showed that Anaconda provides this DLL under a slightly different name: <code>libpython3.4m.dylib</code>. While patching <code>dist/my-script.app/Contents/Info.plist</code> fixes the problem, the <em>right</em> solution is to edit <code>setup.py</code> so that future builds will work correctly. With the help of the <a href="https://pythonhosted.org/py2app/tweaking.html" rel="nofollow">py2app documentation</a>, I put together the following (partial contents of <code>setup.py</code> shown):</p>

<pre><code>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'],
)
</code></pre>

<p>The paths come from the generated <code>Info.plist</code>; 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.</p>

python osx anaconda py2app