3

The Sublime text 2.0.1 (Mac OSX) build command ignores the shebang line a the top of my python file. The shebang line has the full path to my python 3.2 installation :

#!/usr/local/bin/python3

However the python version being used is always 2.7.2. I'm maintaining code for both 2.7 and 3.2 and so must rely on the shebang line to be used.

Is there a way to configure the Sublime text 2 build system to look at the shebang?

Periodic Maintenance
  • 1,698
  • 4
  • 20
  • 32

2 Answers2

2

Sublime does not use the shebang to determine the execution, it uses your build rule. You could customize the Python build rule to add variants for python2 and python3.

Note that with build variants, the default is run by Command+B (Mac) or Control+B (Windows and Linux). The second variant can be run Command+Shift+B (Mac) or Control+Shift+B (Windows and Linux).

Community
  • 1
  • 1
dbn
  • 13,144
  • 3
  • 60
  • 86
  • 1
    I changed Python.sublime-build to point to the full path of python3, and now I can build with python 3. Shame on Sublime Text for not supporting the shebang. BTW on Mac OS, the Python.sublime-build can be found in: ~/Library/Application Support/Sublime Text 2/Packages/Python/Python.sublime-build – Periodic Maintenance Jan 05 '13 at 09:18
  • You should be sure to add your build rule to Packages/User. That way your customizations will not be overridden the next time you upgrade Sublime. – dbn Jan 07 '13 at 18:04
0

Have a look at Sublime Text Shebang plugin.

It adds a few commands that allow to run scripts, based on the shebang line, but the output will be placed on a new buffer, not in the console.

Riccardo Marotti
  • 20,218
  • 7
  • 70
  • 53