Change Python version to evaluate file using SublimREPL plugin

I am using Sublim Text 3 on Mac OS X El Capitan. What I need to do is evaluate the Python file in Sublime Text 3.

I installed Package Control plugins and then SublimREPL .

I installed a two-line layout ( View > Layout > Rows: 2 ) to display the Python interpreter in the second part of the screen.

Then I launch the Python interpreter using Tools > Command Palette... > SublimeREPL: Python .

enter image description here

The interpreter starts correctly, and I get the following:

enter image description here

I cannot find how to start with Python 3.5, which I downloaded manually (thus installed in /usr/local/bin/ ). I tried changing this file: /Library/Application Support/Sublime Text 3/Packages/SublimeREPL/Config/Python/Main.sublime-menu following the instructions of this post , but it didn’t change anything (Python 2.7.10 is still running).

Here is the contents of my Main.sublime-menu :

 [ { "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" } } } ]} ] }] } ] 

Following the tips of this post , I changed part of the code below, but I can not find the exe file in the /usr/local/bin/ :

 {"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"} } } 

When I Ctrl + , + f (according to the doc ), the interpreter still starts with Python 2.7.10.

+5
source share
1 answer

It looks like you are modifying the wrong configuration files, and maybe some of them cause problems.

Then I launch the Python interpreter with Tools > Command Palette... > SublimeREPL: Python

The "SublimeREPL: Python" command palette element is missing, so I assume you mean Tools > SublimeREPL > Python > Python . This will open in a tab something like this:

 # *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. >>> 

In fact, Tools > SublimeREPL > Python displays a menu something like this:

 Python - execnet Python Python - virtualen Python - PDB current file Python - RUN current file Python - IPython 

So far so good. But how to change the version of Python?

Ideally, we could either configure the global python to use (which is not possible), or add a version option to the menu described above (which is also not possible).

The easiest workaround is to add a custom version.

Create a file called Packages/User/Menu.sublime-menu (if it does not already exist). Find the user packages directory through Menu > Preferences > Browse Packages... ). And create your menu in this file. This menu will be added to existing menus.

For instance:

Packages/User/Menu.sublime-menu

 [ { "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"} } } ] }] } ] 

It is important to:

  • The title and identifier do not match any other menu, otherwise it will replace another menu, so I called it above "SublimeREPL options".

  • "cmd" uses the absolute path to the actual binary. You can verify that you are using the correct path with commands like which :

    Find the Python location through which:

     $ which python /usr/bin/python $ which python3 /usr/bin/python3 $ which python2 /usr/bin/python2 

    See also Is it possible to switch between python 2 and 3 on Sublime Text 3 systems? (Windows) for more information.

+3
source

Source: https://habr.com/ru/post/1258126/


All Articles