Python in Sublime 4

see this page and this page for more details.

  1. Open Sublime
  2. Press Ctrl+` to open console
  3. Copy below and paste it to the console, press enter:
    import urllib.request,os,hashlib; h = '817937144c34c84c88cd43b85318b2656f9c3fac02f8f72cbc18360b2c26d139'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
  4. Press Esc
  5. Press Ctrl+Shift+P (or on Mac, Sublime Text -> Preferences -> Package Control)
  6. Type install, press enter (or on Mac, choose Package Control: Install Package)
  7. Type SublimeREPL, press enter
  8. Wait a few seconds for it to install
  9. Go to Preferences -> Key Bindings
  10. Paste this in between the square brackets:
    {"keys": ["ctrl+shift+`"], "command": "repl_open", "args": {"cmd": ["python", "-u", "$file_basename"], "cwd": "$file_path", "encoding": "utf8", "extend_env": {"PYTHONIOENCODING": "utf-8"}, "external_id": "python", "syntax": "Packages/Python/Python.tmLanguage", "type": "subprocess"}},

    You can change the ctrl+shift+` if you want, just make sure it doesn't interfere with a default shortcut
  11. Save the file!
  12. Restart Sublime

Now when you open a python file and press the keybind you set, it will open in a new tab and run the code.