2

I am using Sublime Text 2 on a Mac. I have the SublimeREPL enabled and I am am trying to create a keybinding that that launches a REPL window for a virtual environment located in my virtualenvwrapper folder, ~/Documents/PythonEnvs/

I've tried modifying the code for my keybindings using

Running Python interactively from within Sublime Text 2

as a starting point, followed by Sublime text3 and virtualenvs

and Running Python interactively from within Sublime Text 2

I'm probably missing something completely obvious, but it's actually less and less clear to me now if I need to be writing a plugin, a macro, or (what I thought) just writing a simple key binding to launch the SublimeREPL for Python using a virtual environment.

Has anyone written a keybinding to launch Python in a virtualenv? If so, how did you go about doing it?

The following is in my keybindings file.... it launches a new window that immediately reports "REPL CLOSED." The code doesn't work, or even come close... the best I've managed to do is get it to launch a current Python file in the Python env that comes with Sublime.... but in the interest of showing what I've tried, I've tried modifying my user's sublime-keymap file (latest iteration of that modifying below) for about an hour and a half now... and I can't anything online related to launching a SublimeREPL window in a a VirtualEnv, or anything similar enough that I can figure out how to solve this problem. At this point I gotta throw in the towel and see if anyone else has managed to do it. Thank you in advance for your help, if you have any ideas.

[
    { "keys": ["command+shift+p"], "command": "repl_open", 
                 "caption": "Python - virtualenv",
                 "mnemonic": "p",
                 "args": {
                    "type": "subprocess",
                    "encoding": "utf8",
                    "cmd": ["python", "-u", "$file"],
                    "cwd": "$file_path",
                    "syntax": "Packages/Python/Python.tmLanguage",
                    "external_id": "Python - virtualenv"
                    } 
    }
]
Community
  • 1
  • 1
Evan Volgas
  • 2,900
  • 3
  • 19
  • 30

1 Answers1

0

This should work:

[
 {
    "keys": ["command+shift+p"],
    "command": "repl_open",
    "args": {
        "type": "subprocess",
        "encoding": "utf8",
        "cmd": ["python", "-i", "-u"],
        "cwd": "$file_path",
        "syntax": "Packages/Python/Python.tmLanguage",
        "external_id": "python",
        "extend_env": {"PYTHONIOENCODING": "utf-8"}
    }
 }
]

To get this, I simply checked what sublimeREPL used itself.

Use "args": on line 19 of ~/Library/Application Support/Sublime Text 2/Packages/SublimeREPL/config/Python/Main.sublime-menu for the args in Key Bindings -- User

Side note:

To switch from version 2.7 to 3, replace

"cmd": ["python", "-i", "-u"],

with

"cmd": ["python3", "-i", "-u"],
WickedJargon
  • 203
  • 2
  • 9