Ways to invoke python and Spyder on OSX

Viewed 64837

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.

9 Answers

A very simple method not requiring use of Terminal is essentially to create a spyder.app package in Applications and copy the spyder exec file from Anaconda into this folder. Clicking on the package will run spyder as an app, and you can right-click the dock icon to keep it in the dock.

Below are the step-by-step instructions.

We first create the spyder.app folder in Applications:

  1. Open the Applications folder in Finder.

  2. Right-click and create "New Folder".

  3. Name the folder "spyder.app" and allow the .app extension.

We then copy the exec spyder file:

  1. In a new Finder window, open your home folder (it should have a simple picture of a house as the icon). A shortcut is to press shift+command+H while Finder is open.

  2. Open the anaconda3 folder, and then open the folder named 'bin'.

  3. Locate the exec file named 'spyder', and right-click to copy the file.

Note: if anaconda3 isn't installed in your home directory, just search for 'anaconda3' with exact filename matches in Finder and open the file.

Paste the copied exec file into the spyder.app package:

  1. In the Finder window open to Applications, right-click the spyder.app created above and select "Show Package Contents".

  2. Right-click in the window and paste the exec file.

Now, when you return to the Applications folder, double-click on the spyder.app package and spyder should run. Right-click the icon in the dock and select "Keep in Dock" to keep the app in the dock when not running. You can also create the icon for the app as indicated in 4 and 5 of the original answer.

I believe that the simplest way for access to spyder in macOS is via terminal! you keep in the dock the terminal and when you want to open spyder, you open terminal and type spyder in a terminal and then return key! I like this method because when I open a terminal and I press up arrow once or few times I will access to spyder and run it with press return! I know that it is a very obvious and easy method but I wanted to remind it!

A super quick way with no skill at all is to find the exe (which sypder will achieve this) in something like //anaconda3/bin/spyder. Duplicate this file and put it on your desktop. Whenever you need it just double click.

Note the reason I suggest this as an alternative is because on my work machine, I do not have access to change anything the Applications directory.

Edit: An even faster way would just be to do: command + spacebar then type Spyder.

The easiest one is to download official Spyder.app from https://github.com/spyder-ide/spyder/releases (choose the version that matches the version in Anaconda, not the latest one; lite version is enough). Install then you can even associate .py files with this app.

p.s. I tried hard by making my own Spyder.app, but it won't accept a file path as a parameter when I launch the app. So save your time and use the official one.

Related