Change Python version for evaluating file with SublimREPL plugin
<p>I am using Sublim Text 3 on Mac OS X El Capitan. What I need to do is to evaluate a Python file within Sublime Text 3.</p>

<p>I have installed <code>Package Control</code> and then <code>SublimREPL</code> plugins.</p>

<p>I have set up a 2 rows layout (<code>View &gt; Layout &gt; Rows: 2</code>) in order to display a Python interpreter in the second part of the screen.</p>

<p>I then launch the Python interpreter with <code>Tools &gt; Command Palette... &gt; SublimeREPL: Python</code>.</p>

<p>The interpreter starts correctly and I get this:</p>

<p><a href="https://i.stack.imgur.com/TXBS0.png" rel="nofollow"><img src="https://i.stack.imgur.com/TXBS0.png" alt="enter image description here"></a></p>

<p>I can't find how to start with Python 3.5 that I have downloaded manually (thus installed in <code>/usr/local/bin/</code>). I have tried to modify this file: <code>/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/Config/Python/Main.sublime-menu</code> following <a href="http://stackoverflow.com/a/17575258/2508539">this post</a> instructions, but this did not change anything (Python 2.7.10 still launched).</p>

<p>Here is the content of my <code>Main.sublime-menu</code>:</p>

<pre><code>[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "R",
            "id": "SublimeREPL",
            "children":
            [
                {"caption": "Python",
                "id": "Python",

                 "children":[
                    {"command": "repl_open",
                     "caption": "Python",
                     "id": "repl_python",
                     "mnemonic": "P",
                     "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"}
                        }
                    },
                    {"command": "python_virtualenv_repl",
                     "id": "python_virtualenv_repl",
                     "caption": "Python - virtualenv"},
                    {"command": "repl_open",
                     "caption": "Python - PDB current file",
                     "id": "repl_python_pdb",
                     "mnemonic": "D",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - RUN current file",
                     "id": "repl_python_run",
                     "mnemonic": "R",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python", "-u", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - IPython",
                     "id": "repl_python_ipython",
                     "mnemonic": "I",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "autocomplete_server": true,
                        "cmd": {
                            "osx": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "linux": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
                        },
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {
                            "PYTHONIOENCODING": "utf-8",
                            "SUBLIMEREPL_EDITOR": "$editor"
                        }
                    }
                    }
                ]}
            ]
        }]
    }
]
</code></pre>

<p>Still following <a href="http://stackoverflow.com/a/17575258/2508539">this post</a> advices, I modified the part of code below, but I can't find any exe file in folder <code>/usr/local/bin/</code>:</p>

<pre><code>{"command": "repl_open",
"caption": "Python - PDB current file",
"id": "repl_python_pdb",
"mnemonic": "D",
"args": {
    "type": "subprocess",
    "encoding": "utf8",
    "cmd": ["/usr/local/bin/python3", "-i", "-u", "-m", "pdb", "$file_basename"],
    "cwd": "$file_path",
    "syntax": "Packages/Python/Python.tmLanguage",
    "external_id": "python",
    "extend_env": {"PYTHONIOENCODING": "utf-8"}
    }
}
</code></pre>

<p>When I press <code>Ctrl</code> + <code>,</code> + <code>f</code> (according to the <a href="https://github.com/wuub/SublimeREPL/blob/master/README.md" rel="nofollow">doc</a>), the interpreter still starts with Python 2.7.10.</p>

<p>It appears you are modifying the incorrect configuration files and perhaps a few things are causing issues.</p>

<blockquote>
  <p>I then launch the Python interpreter with <code>Tools &gt; Command Palette... &gt; SublimeREPL: Python</code></p>
</blockquote>

<p>There is no command palette item "SublimeREPL: Python", so I'm assuming you mean <code>Tools &gt; SublimeREPL &gt; Python &gt; Python</code>. That opens in a tab something like the following:</p>

<pre><code># *REPL* [python]
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; 
</code></pre>

<p>In fact <code>Tools &gt; SublimeREPL &gt; Python</code> displays a menu something like the following:</p>

<pre><code>Python - execnet
Python
Python - virtualen
Python - PDB current file
Python - RUN current file
Python - IPython
</code></pre>

<p>So far so good. But how to change the Python version?</p>

<p>Ideally we could either configure the global python to use (that doesn't seem possible) or add a version variant to the menus desccribed above (that doesn't seem possible either).</p>

<p>The most straight forward workaround is adding a custom version variant.</p>

<p>Create a file named <code>Packages/User/Menu.sublime-menu</code> (if it doesn't already exist). Find the User packages  directory via <code>Menu &gt; Preferences &gt; Browse Packages...</code>). And create your menu in that file. This menu will be <strong>added</strong> to the existing menus.</p>

<p>For example:</p>

<p><code>Packages/User/Menu.sublime-menu</code></p>

<pre><code>[
    {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL Variants",
            "id": "SublimeREPLVariants",
            "children":
            [
                {
                    "command": "repl_open",
                    "caption": "Python - PDB current file",
                    "id": "repl_python_pdb",
                    "mnemonic": "D",
                    "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["/usr/bin/python3", "-i", "-u", "-m", "pdb", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                    }
                }
            ]
        }]
    }
]
</code></pre>

<p>It is important that:</p>

<ol>
<li><p>The caption and id are not the same as any other menu otherwise it will replace the other menu, hence I've named the one above "SublimeREPL Variants".</p></li>
<li><p>The "cmd" uses an absolute path to a valid binary. You can check you are using the correct path with a commands like <code>which</code>:</p>

<p>Find the location of Python via which:</p>

<pre><code>$ which python
/usr/bin/python

$ which python3
/usr/bin/python3

$ which python2
/usr/bin/python2
</code></pre>

<p>See also <a href="https://stackoverflow.com/questions/40024713/possible-to-switch-between-python-2-and-3-in-sublime-text-3-build-systems-wind/40031389#40031389">Possible to switch between python 2 and 3 in Sublime Text 3 build systems? (Windows)</a> for additional details.</p></li>
</ol>

python osx sublimetext3 osx-elcapitan sublimerepl