Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways to invoke python and Spyder on OSX

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. Launch Spyder without having to go through the Launcher application (say, by typing things into Spotlight and Quicksilver)
  2. Run Python code from the Finder, presumably by double-clicking on my .py file or by selecting and and pressing Cmd-O
  3. Run Python code by typing a Python script's name into Quicksilver (as if it was a regular program)

Here's what I've tried:

  1. (nothing; no ideas here)
  2. I've associated .py files with /Users/kuzzooroo/anaconda/python.app/Contents/MacOS/python and made them executable (chmod u+x). When I try to run the application never launches and I don't get an error message (don't know where to look)
  3. Made the files executable and tried to run them from Spotlight. Same result as #2.

Here's what I can do:

  • 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

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.

like image 387
kuzzooroo Avatar asked Dec 21 '13 21:12

kuzzooroo


People also ask

How do I open a Spyder Python on a Mac?

To start Spyder, type the name spyder in a terminal or at the Command Prompt. The Python 2.7 version of Anaconda also includes a graphical Launcher application that enables you to start IPython Notebook, IPython QTConsole, and Spyder with a single click. On Mac, double click the Launcher.

How do I launch Spyder in Python app?

From the command line: Type spyder in your terminal (or Anaconda prompt on Windows). From Anaconda Navigator: Scroll to Spyder under Home, and click Launch.


1 Answers

To make spyder callable from Spotlight or Finder:

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

    which spyder 

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

  2. 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 

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

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

Optional:

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

  2. 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.

like image 146
Thomas Avatar answered Sep 28 '22 13:09

Thomas