I used SublimeREPL happily, then I wanted "Open with SubilimeText" option to be on right-click. So I installed Sublime Text (without removing) with "Add to explorer context menu" checked. And now when I press F7 SublimeREPL does nothing.
The only way it runs Python files is
Tools > SublimeREPL > Python > RUN Current File
I tried to remove REPL.build-system, re-installing package. Doesn't help.
How can I fix it?
I have found the fix faster than you guys but thanks anyways :).
If anybody have the same problem this may help:
Open Sublime Text > Go to Preferences > Key Bindings
In "Key Bindings - User" tab paste the following code (Note: I set key "F7", but any other free key can be set):
[
{
"keys": ["f7"],
"command": "repl_open",
"args": {
"cmd": ["python", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"encoding": "utf8",
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"external_id": "python",
"syntax": "Packages/Python/Python.tmLanguage",
"type": "subprocess"
}
}]
Related
I have my Sublime Text 3 set up with Python so that when I hit my hotkey for "build", it uses my custom Python build (given below). What it does is build/run the code through the python compiler via cmd (command prompt). Thus I get my outputs in the windows cmd.
Problem is, after the program terminates I am left with a blank cmd window. What I want is for it to stay in interactive Python mode (so that I can print out variables that are in the memory, etc.). How could I achieve this?
The custom Python+cmd build:
{
"cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],
"path": "C:\\MinGW\\bin\\",
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
I would like to configure a second build system for Python on Sublime text 3. By default it use Python 2.7. for the time being, if I want to use Python 3.5, I execute activate py35 and it works like a charm.
Here is my original build system :
{
"cmd": ["start", "cmd", "/k", "python", "-u", "-i", "$file"],
"selector": "source.python",
"shell": true,
"working_dir": "$file_dir"
}
I added this line just before :
"cmd": ["activate", "py35"],
I've found this question but it didn't help, which command isn't recognized, even if my env is activated :
You can't add another "cmd". JSON doesn't allow duplicate keys.
You also don't need to activate anything. Give the full path to the Python executable
For example
"cmd": ["start", "cmd", "/k", "C:/Users/name/path/py35/Scripts/python",
This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 6 years ago.
Is it possible to set up sublime text for full stack python development. By this, I mean the following:
1. python shell where I can input an expression and instantly get the result,
2. the shell will work for the 'input' method, which will prompt the user to enter data.
I have installed the theme and color scheme, but the console/shell is not working or I did not get the correct package from the package control. I want an environment where I can work in the sublime text without shifting into the IDLE. Please help me kindly if you know how to do it.
There are several ways to do this:
As #cricket_007 states you can install SublimeREPL and run the current file via Tools >>> SublimeREPL >>> Python >>> Python - Run current file. This interprets the python file in a Sublime Text view and inputs are possible. However since this is not a build system you can create a build system from this (click Tools >>> Build System >>> New Build System... and paste):
{
"target": "repl_open",
"encoding": "utf8",
"syntax": "Packages/Python/Python.tmLanguage",
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"type": "subprocess",
"cmd": ["python", "-u", "$file"],
"cwd": "$file_path",
"external_id": "python",
"selector": "source.python"
}
As an alternative one could run the file in a terminal, by using the following build system. This will create a new terminal and execute the file in python and afterwards await pressing enter.
{
"selector": "source.python",
"windows": {
"shell_cmd": "start \"$file_name\" cmd /c \"python $file_name & pause\""
},
"linux": {
"shell_cmd": "xterm -T \"$file_name\" -e bash -c \"python $file_name; echo Press enter to exit... & read\""
}
}
Feel free to add the osx option
Basically, I've installed Sublime Text 2 to write in Python.
I then installed Package control and via package control I search "SublimeREPL" and I install the package, however even after installing, when I select Python through Tools > SublimeREPL > Python > Python, I get the error:
WindowsError(2, 'The system cannot find the file specified.')
Any help please? I'm pretty new to this.
Go to preferences -> Keybindings - User
and paste this. Make sure there are only one set of [] in your file, if you have custom keybinds set already then add a , after your last } then paste everything but the [] at the beginning and end after your ,.
[
{ "keys": ["ctrl+shift+r"], "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"
}
}
]
Save and quit Sublime Text.
Follow these instructions
How to add to the pythonpath in windows 7?
You should now be able to run your current file in repl with crtl+shift+r
Open sublime text and create a new file. Save it as hello.py
Type:
print('Hello World')
Save then hit ctrl-shift-r
See if that works
I am able to set python3.2 for the build command in sublime text 2(and build with python3.2), but when invoking the console with cmd-` the interpreter is mac's default 2.6 version.
Any help is greatly appreciated!
The console in Sublime Text 2 uses the internal version of Python, which is 2.6. There is no way to change it without breaking a whole bunch of stuff. There is a workaround, though. If you just want a Python console within ST2, use the awesome SublimeREPL package, which can also be installed through Package Control. Among many other things, you can send selections or whole files to be interpreted through a REPL of your choice, including Python 3. Create Packages/User/SublimeREPL/config/Python/Main.sublime-menu with the following contents:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Python",
"id": "Python",
"children":[
{"command": "repl_open",
"caption": "Python 3",
"id": "repl_python3",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]
}
]
}]
}
]
changing the "cmd" option to the full path to your python3 binary. This way your changes will survive any SublimeREPL upgrades. BTW, this path works for any package, so you can feel free to customize away without fear of accidentally losing it all.
Cmd+` is supposed to open Sublime Text's embedded interpreter console, i.e. the one that you use when developing or debugging Sublime plug-ins. You can verify that by noticing that the sublime module is available.
If you really want Python 3 console there, upgrade to Sublime Text 3 which embeds Python 3.3. Alternatively, use a dedicated plug-in like SublimeREPL (see #MattDMo's answer).
And BTW: If you want a nice environment for interactive Python work, I suggest to disregard the above and give IPython Notebook a shot.
You could try setting the environment variables something similar to the following in Tools > Build System > New Build System
{
"path": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"env":
{
"PYTHONPATH":"/usr/local/lib/python:/usr/local/username/python/3.2/lib/python3.2/"
},//this comma!
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
What you're seeing is the Python that comes bundled with Sublime Text. I wouldn't upgrade it, but if you want to use your own you could do something like:
ln -s $HOME/.pythonbrew/pythons/Python-2.6/lib/python2.6 /Your_Sublime_Install_Path/lib/python2.6