<p>接受的答案有两个缺点:启动spyder时会出现控制台窗口,并且无法将spyder图标保留在停靠点中。通过为spyder创建一个合适的Mac应用程序包可以避免这些缺点,这非常容易做到。</p>
<p>要将<code>/usr/local/bin/spyder3</code>(计算机上<code>which spyder3</code>的结果)转换为传统的Mac应用程序,请执行以下操作:</p>
<ol>
<li><p>创建Mac应用程序包(基本上是包含可执行文件的文件夹结构):</p>
<pre><code>cd /Applications
mkdir -p spyder.app/Contents/MacOS
echo -e '#!/bin/bash'"\n /usr/local/bin/spyder3 $@" >> spyder.app/Contents/MacOS/spyder
chmod +x spyder.app/Contents/MacOS/spyder
</code></pre></li>
<li><p>在Contents文件夹(即spyder.app/Contents/Info.plist)中创建一个名为Info.plist的纯文本文件,其中包含以下内容:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleExecutable</key>
<string>spyder</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>3.1.4</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3.1.4</string>
</dict>
</plist>
</code></pre></li>
<li><p>(可选)创建应用程序图标,如接受答案的步骤4和5所示。</p></li>
</ol>
<p>喂,spyder突然变得对Mac更友好了!</p>
<p><strong>编辑:<br/>可以通过以下方式进一步提高spyder的mac友好性:</p>
<ol>
<li><p><strong>防止普通python火箭图标出现在spyder图标旁边</strong><br/>
为此,请在spyder中取消选中“工具”->;“首选项”->;“iPython控制台”->;“图形”->;“激活(matplotlib)”</p></li>
<li><p><strong>使spyder成为.py文件的默认编辑器。</strong><br/>
这个更棘手。首先确保spyder.app/Contents/MacOS/spyder的内容为</p>
<pre><code>#!/bin/bash
/usr/local/bin/spyder $@
</code></pre></li>
</ol>
<p>然后创建一个包含单个操作“执行shell脚本”的自动机脚本。在其中粘贴以下(bash)脚本:</p>
<pre><code>for f in "$@"
do
open /Applications/spyder.app --args $f
done
if [ -z "$f" ]; then
open /Applications/spyder.app --args ~
fi
</code></pre>
<p>为输入数据选择“As argument”,如下面的屏幕截图所示(屏幕截图中缺少“--args~”,但需要避免在没有任何文件的情况下启动spyder时出错)。
<a href="https://i.stack.imgur.com/vyJsX.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/vyJsX.jpg" alt="automator script"/></a>
<br/>
例如,将此脚本另存为名为“spydropener”的应用程序。</p>
<p>使spydropener成为打开.py文件的默认应用程序(在.py文件上使用Finder“Get Info”对话框)</p>