在 OSX 上调用 python 和 Spyder 的方法 [英] Ways to invoke python and Spyder on OSX

查看:27
本文介绍了在 OSX 上调用 python 和 Spyder 的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近购买了一台 MacBook,并通过 Anaconda 在其上安装了 Python.这是版本信息:

I recently bought a MacBook and install Python on it via Anaconda. Here's the version information:

Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Nov 11 2013, 10:49:09) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

我希望能够做以下所有事情:

I'd like to be able do all of the following:

  1. 无需通过启动器应用程序即可启动 Spyder(例如,通过在 Spotlight 和 Quicksilver 中输入内容)
  2. 从 Finder 运行 Python 代码,大概是通过双击我的 .py 文件或选择并按下 Cmd-O 来实现
  3. 通过在 Quicksilver 中输入 Python 脚本的名称来运行 Python 代码(就像它是一个常规程序一样)

这是我尝试过的:

  1. (什么都没有;这里没有想法)
  2. 我已将 .py 文件与/Users/kuzzooroo/anaconda/python.app/Contents/MacOS/python 相关联并使其可执行(chmod u+x).当我尝试运行应用程序时,它永远不会启动,并且我没有收到错误消息(不知道在哪里查看)
  3. 使文件可执行并尝试从 Spotlight 运行它们.结果与 #2 相同.

这是我可以做的:

  • 如果我在顶部有正确的 shebang 并且已使文件可执行,则从终端窗口运行我的代码
  • 使用 py2app 生成应用程序.不幸的是,这种方法存在以下缺点:
    • 我经常修改我的脚本,不希望每次都运行 py2app
    • 即使是一个简单的脚本,生成的应用程序也是 7 MB
    • 要在某些情况下运行应用程序,我必须在包中四处寻找实际的Unix 可执行文件"并运行它

    一旦我有这个工作,我有兴趣做以下事情:
    A. 控制哪些脚本在运行时创建控制台窗口,哪些不创建
    B. 控制生成的控制台窗口在脚本完成时是否消失或等待用户(我)关闭它
    但是,我怀疑一旦我首先弄清楚我将如何调用我的脚本,就很容易弄清楚如何执行这些操作(或者是否可能).

    Once I have this working, I'm interested in doing the following:
    A. Controlling which scripts create a console window when they run and which do not
    B. Controlling whether the resulting console window disappears when the script completes or waits around for the user (me) to close it
    However, I suspect it may be easy to figure out how to do these (or whether it's possible) once I've figured out how I'm going to invoke my scripts in the first place.

    推荐答案

    使 spyder 可以从 Spotlight 或 Finder 中调用:

    To make spyder callable from Spotlight or Finder:

    1. 通过在终端中运行来定位您的 spyder 可执行文件所在的位置:

    1. Locate where your spyder executable is by running in Terminal:

    which spyder
    

    如果你通过 Anaconda 安装了 spyder,这应该产生 ~/anaconda/bin/spyder,如果你使用 MacPorts 或类似的东西,则产生 /opt/local/bin/spyder.

    This should yield ~/anaconda/bin/spyder if you installed spyder via Anaconda, /opt/local/bin/spyder if you used MacPorts or something similar.

    在您的 Applications 目录中创建一个名为 spyder 的文件并使其可执行.然后,用上一个命令的输出填充它,然后是 &;退出:

    Create a file called spyder in your Applications directory and make it executable. Then, fill it with the output of the previous command, followed by a &; exit:

    touch /Applications/spyder
    chmod +x /Applications/spyder
    echo -e '#!/bin/bash'"
    ~/anaconda/bin/spyder &
    exit" >> /Applications/spyder
    

    (如果你使用不同的 shell(例如 tcsh),用那个替换 bash)

    (if you use a different shell (e.g. tcsh), replace bash by that)

    在终端->首选项->配置文件->默认配置文件"->外壳->当外壳退出时:选择如果外壳干净退出则关闭"

    Under Terminal -> Preferences -> Profiles -> "default profile" -> Shell -> When the shell exits: Select "Close if the shell exited cleanly"

    可选:

    1. 这里下载spyder图标并打开在预览中.按 cmd+C 复制其内容.

    1. Download the spyder Icon from here and open it in Preview. Copy its contents by hitting cmd+C.

    在 Finder 中,找到 /Applications/spyder 并按 cmd+I 打开其获取信息"窗格.用鼠标选择左上角的图标,然后按 cmd+V.

    In Finder, locate /Applications/spyder and open its "Get Info" pane by hitting cmd+I. Select the icon in the top left corner with your mouse and hit cmd+V.

    这篇关于在 OSX 上调用 python 和 Spyder 的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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