How to associate py extension with python launch on Mac OS X?

Does anyone know how to associate the py extension with the python interpreter in Mac OS X 10.5.7? I got to the application with which it can be associated (/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python), but the python executable appears as a non-selectable item with gray color. Any ideas?

+4
source share
4 answers

Python.org OS X Python installers include an application called "Python Launcher.app" that does exactly what you want. It is installed in / Applications / Python nn / for nn> 2.6 or / Applications / MacPython nn / for 2.5 and earlier. In the preferences pane, you can specify which Python executable should run; it can be any command line path, including installed by Apple, on / usr / bin / python 2.5. You also need to make sure that .py is associated with the "Python Launcher"; you can use the Finder Get Info command to do this, as described elsewhere. However, keep in mind that this can be a security risk if downloaded .py scripts run automatically in your browser. (Note that Apple-supplied Python in 10.5 does not include "Python Launcher.app").

+6
source

Steve, add the following to the top of your python script:

#!/usr/bin/env python 

It should be like the first line of the file.

Then make the executable like this:

 daves-macbookpro ~: chmod +x foo.py 

Then all you need to do to run is type

 ./foo.py 
+2
source

File associations are performed using the "Get Information". You select your .PY file, select the "File" menu; Get the menu item "Information".

In the middle of the Get Info page, β€œOpen With” is displayed.

You can choose the Python Launcher. There is a Change All .. button that changes the link for all .py files.

+2
source

The default python installation (at least 10.6.8) includes Python Launcher.app in /System/Library/Frameworks/Python.framework/Resources/ , which is smoothed to the latest / current version of Python installed on the system. This application launches the terminal and sets the correct environment for running the script.

0
source

All Articles