How to Run Python Code from Sublime Text 2

Sublime Text 2 - running selected python code in the interpreter

There are two choices I think, one can be using PdbSublimeTextSupport, available here: http://pypi.python.org/pypi/PdbSublimeTextSupport

Or you can try SublimeREPL, that can run Python code: https://github.com/wuub/SublimeREPL

How to Run Python Code on SublimeREPL

First "Install Package Control" from https://sublime.wbond.net/installation#st2

Optional(To check the above package is successfully installed:
Click the Preferences > Browse Packages… at this folder
Click Back Button one time and then into the Installed Packages/ folder, check there will be Package Control.sublime-package file
)

then go to Preferences > Package Control > Package Control: Install Package in sublime text 2

find SublimeREPL in list.

Restart SublimeText2

open Preferences > Package Settings > SublimeREPL > Settings - Default file copy all text from there.

then open Preferences > Package Settings > SublimeREPL > Settings - User and paste the text here.

Restart SublimeText2

Go to Tools > SublimeREPL > Python > Python

And you are done

How to run code in Sublime text 2 python

Instead of adding python to the path, I prefer simply specifying the full path to python in the sublime build. Python.exe is probably installed in one of these (or something similar)

C:/Python
C:/Program Files/Python
C:/Program Files (x86)/Python
etc...

Once you found it (lets say its in C:\Program Files (x86)\Python27) edit the sublime_build for python. Here is the build I use:

{
"cmd": ["C:\\Program Files (x86)\\Python27\\python.exe","-u","$file"],
"selector": "source.python"

}

for me, this file is in

Sublime Text\Data\Packages\Python\Python.sublime-build

Running python in Sublime Text 2 getting error

You need to add the python directory to your system's path environment variabe.
To do that in windows you need go to Control Panel> System and Security > System > Advanced System Settings> in the advanced tab go to Environment Variables. In the environment variables in the System Variables area scroll down until you find Path. Select it and press Edit. Then a window should appear titled Edit System Variable where you have the variable name (should be path) and the variable value which is a long string. At the start of the string you need to manually add the python's directory. For example my python 2.7 directory is at *C:\Python27* So you need to add C:\Python27\ at the start of the string. So after you do that the value should now look something like that:

C:\Python27\;C:\Program Files etc..

Try that and tell us the results :)

Hope that helped

Cheers,
Alex



Related Topics



Leave a reply



Submit