I have recently downloaded Sublime Text 3 and since it does not have a Python shell, I have downloaded SublimeREPL, but every time I run the code by SublimeREPL >>> Python >>> Python - Run current file I get ***Repl Closed*** text after the output, which prevents me from interacting with the shell. Is there any way around this?
Well not 100% convinced by SublimeREPL, but let's get straight to the solution :
Find the Python configuration
~/.config/sublime-text-3/Packages/SublimeREPL/config/Python/Main.sublime-menu
add the -i flag to the python command in this section (you're also free to create a new one)
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i" ,"-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
Now the interpreter stays open upon program completion.
Related
I have installed the python 3.5 interpretor in my device (Windows).
Can anybody guide me through the process of using packages to run it like SublimeREPL?
Yes, you can use any Python version you want to run programs from Sublime - you just need to define a new build system. Select Tools -> Build System -> New Build System, then delete its contents and replace it with:
{
"cmd": ["C:/Python35/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
assuming that C:/Python35/python.exe is the correct path. If python.exe resides someplace else, just put in the correct path, using forward slashes / instead of the Windows standard backward slashes \.
Save the file as Packages/User/Python3.sublime-build, where Packages is the folder opened by selecting Preferences -> Browse Packages... - Sublime should already automatically save it in the right directory. Now, there will be a Tools -> Build System -> Python3 option that you can select for running files with Python 3.
For details on setting up SublimeREPL with Python 3, please follow the instructions in my answer here.
if you have installed python3 and SublimeREPL, you can try setting up key bindings with the correct path to the python3 file.
[
{
"keys":["super+ctrl+r"],
"command": "repl_open",
"caption": "Python 3.6 - Open File",
"id": "repl_python",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["The directory to your python3.6 file", "-i", "$file"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]
You can try by copying this code into your /Sublime Text 3/Preferences/Key Bindings/
Hope this helps!
I'm trying to run Python on SublimeREPL, but python is not on interactive mode.
So when I send a line to sublimeREPL, it just shows something if it's an error or if I print something.
How can I change python to interactive mode?
Found a solution:
After setting up Python on SublimeREPL, go to Keybindings - User and add this code below. It will be just like the normal PythonIDE!
[
{ "keys": ["f8"], "command": "repl_open",
"caption": "Python",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i", "-u", "$file"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python"
} }
]
I'm not understanding your problem with that? Python will only log data to the console if you print something or it encounters an error, there is nothing else to show usually.
Regardless, Python should be preconfigured on SublimeREPL. Look at the documentation, and if that doesn't help then look at this guide. However it doesn't sound like there's anything going wrong.
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"
}
}
]
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"],
I really like using sublime text 2 to write Python codes, however any time I try to run a script which has an input, the sublime text console reports an error. So, I decided to try SublimeREPL, however I've been searching for hours and I didn't find out how to run Python code...
could you guys help me?
I want to run the code on SublimeREPL as we do with the sublime text console (CTRL+b).. what I actually want to know is whether or not there's a way to do the same with SublimeREPL.
Thank you in advance!
As described here, create a new Build System file and save it as ..\Packages\User\SublimeREPL-python.sublime-build. The file should contain:
{
"target": "run_existing_window_command",
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
Then go to your Python file tab and select Tools > Build System > SublimeREPL-python. Now, Ctrl + B should execute the current Python file, with the output in a new tab. If you use a two column layout, the REPL output should open in the second column. (This was using Sublime Text 3.)
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
Steps to make Sublime Python Console which is Interactive and Reusable :
1) Install SublimeREPL plugin :
In Top Bar > "Tools" > "Command Palette" > "Package Control: Install Package"
Search for : "SublimeREPL" and install
2) Create Build System :
In Top Bar > "Tools" > "Build System" > "New Build System"
Replace all contents of the file with :
{
"target": "run_existing_window_command",
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
Save the file as "PythonRepl.sublime-build" in the default "user" folder.
3) Settings to make Console interactive and Reusable:
|=> Goto "Preferences" > "Browse Packages"
|=> Goto Folder : SublimeRepl
|=> Edit : sublimerepl.py
Replace : if view.id() == view_id
With : if view.name() == view_id:
|=> Goto Folder : SublimeRepl/config/Python
|=> Edit : Main.sublime-menu
|=> Under "caption": "Python - RUN current file"
|=> Append : "-i", in "cmd" as :
"cmd": ["python", "-u", "$file_basename"],
"cmd": ["python", "-i", "-u", "$file_basename"],
|=> Add : Before "external_id": "python"
"view_id": "*REPL* [python]",
|=> Full Code as shown below :
--------------------------------------------------
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"view_id": "*REPL* [python]",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
4) Using :
4.1) Open the Python file that you want to run in Sublime Text.
4.2) In Top Bar > "Tools" > "Build System" > "PythonRepl".
4.3) Build the Python file, by choosing In Top Bar > "Tools" > "Build"
or
Using either the build shortcut (Ctrl+B for Windows, or ⌘ Command+B for Mac)
I want to expand on #sblair's response. #alexpmil asked in a comment how to prevent the REPL from closing.
In Sublime, go to Sublime Text > Preferences > Browse Packages
In your packages, open SublimeREPL\config\Python\Main.sublime-menu.
Find the part that contains id: repl_python_run.
Under args/cmd, add -i. That's it.
For reference, mine looks like the following:
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["C:/Python34/python", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
I use python portable along with sublime portable of a memory stick and decided to install sublime REPL however when trying to use python portable as the build path for sublimerepl it does not specify it.
To put it simply I can't specify the sublimerepl python path like I can with straight sublime text!
I have tried adding the following into SublimeREPL.sublime-settings
"default_extend_env": {"PATH": "{PATH}:C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe"},
I have also tried changing:
"cmd": ["python", "-i", "-u"],
to
"cmd": ["C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe", "-u", "$file"],
within Python/Main.sublime-menu
Note in normal sublime I add the following to Python.sublime-build:
{"cmd": ["C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe", "-u", "$file"],"file_regex": "^[ ]*Iile \"(...*?)\", line ([0-9]*)","selector": "source.python"}
Any ideas?
Thanks,
Andrew
Is it possible you're changing the wrong line of code in /Packages/SublimeREPL/config/Python/Main.sublime-menu? If you wish to run REPL on the current file,
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["C:\\Users\\Andy\\Documents\\_Main\\M-Stick Backups\\08.07.13\\Computing\\Python Portable\\Portable Python 2.7.3.1\\App\\python.exe", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
is what the modified section should look like. (It appears you might be modifying the command which opens the interpreter in interactive mode as opposed to running the current file).
Thanks to Hower... I installed the package control, then the sublimePREPL package and, then in the keybinding (under preferences) I wrote this int the user file:
[
{"keys": ["ctrl+b"], "command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["C:\\Users\\giova\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}}
]