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

查看:97
本文介绍了在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. 无需通过Launcher应用程序即可启动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可执行文件"并改为运行它.
    • Run my code from a Terminal window, if I have the right shebang on top and have made the file executable
    • Generate an application using py2app. Unfortunately, this method suffers the following drawbacks:
      • I frequently modify my scripts and would prefer not to have to run py2app every time I do
      • Even for a trivial script the resulting app is 7 MB
      • To run the application in some contexts I have to dig around in the bundle to find the actual "Unix Executable File" and run that instead

      完成这项工作后,我会对以下操作感兴趣:
      A.控制哪些脚本在运行时创建控制台窗口,哪些不运行
      B.控制脚本完成时或控制台中等待用户(me)关闭时,结果控制台窗口是否消失
      但是,我怀疑一旦弄清楚我将如何首先调用脚本,就很容易弄清楚如何执行这些操作(或是否可行).

      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.

      推荐答案

      要从Spotlight或Finder调用spyder:

      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的文件并使其可执行.然后,用上一个命令的输出填充,后跟&; exit:

      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'"\n~/anaconda/bin/spyder &\nexit" >> /Applications/spyder
      

      (如果您使用其他外壳(例如tcsh),请用该外壳替换bash)

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

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

      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天全站免登陆