Setting python path for sublimerepl from sublime text? - python

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

Related

Sublime Text 3 shows EOFError() when I try to run Python scripts with SublimeREPL

When I try to run a Python script from Sublime Text 3, I get a pop-up dialog box that simply says "EOFError()" and nothing else.
I'm using the SublimeREPL plugin, with some slight modifications to my C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\config\Python\Main.sublime-menu file (based off this video: https://www.youtube.com/watch?v=wM2LbXCkLDI ) so I can get an interactive shell opened in a separate tab that runs the program. The main change I made was adding the "-i" command line argument to the Python interpreter to run the interactive shell after the script finishes.
This has worked fine before. I'm not sure what changed in my configuration or Python or the SublimeREPL package to make it no longer work.
Here is my Main.sublime-menu file:
[
{
"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", "-i", "-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"
}
}
}
]}
]
}]
}
]
UPDATE: When I look at the Sublime Text console, it shows this error after I tried to run a Python script:
Traceback (most recent call last):
File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 495, in open
rv = ReplView(view, r, syntax, repl_restart_args)
File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 186, in __init__
self._history = PersistentHistory(self.external_id)
File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 140, in __init__
self._db.create("external_id", "command", "ts", mode="open")
File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repllibs\PyDbLite.py", line 193, in create
return self.open()
File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repllibs\PyDbLite.py", line 246, in open
self.fields = pickle.load(_in)
EOFError
error: EOFError()
I tried uninstalling and reinstalling SublimeRepl, then restarting Sublime Text, but I get the same error message.
I did some debugging, and found the _in was a file object of C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\User\.SublimeREPLHistory\python.db, an 819kb file. I tried deleting it (backing it up to another folder first) and restarting Sublime Text. This seemed to have worked! I guess somehow some null character was written to the history file? It works now. Thanks to MattDMo for pointing me to the Sublime Text console where I could find the error message.
I fixed this myself by deleting C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\User\.SublimeREPLHistory\python.db (though it'll be in a different folder for you depending on your username) and restarting Sublime Text.
I guess somehow some null character was written to the history file? It works now. Thanks to MattDMo for pointing me to the Sublime Text console where I could find the error message.

python shell in Sublime text 3

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.

Python interactive mode on SublimeREPL

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.

SublimeREPL and IPython

I fail when I tried to use IPython with SublimeREPL.
My setup is:
- Windows 8.1
- Sublime Text 3
- C:\Python34
- C:\Python27
- C:\Anaconda3\Scripts -> Here it's where Ipython is
My PYTHONPATH and PATH are correct and I wrote in SublimeREPL settings - User:
{
"default_extend_env": {"PATH": "{PATH};C\\Anaconda3\\Scripts"}
}
It's solved. I make a file named Main.sublime-menu within the folder Sublime Text 3\Packages\User\SublimeREPL\config\Python
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{
"caption": "Python",
"id": "Python",
"children":[
{
"command": "repl_open",
"caption": "IPython - Anaconda",
"id": "repl_python_ipython",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": ["C:/Anaconda3/Scripts/ipython", "--colors=NoColor"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python"
}
}
]
}
]
}]
}
]
SublimeREPL doesn't run ipython executable directly - it uses its API to start the console, therefore IPython needs to be importable, what means it needs to be on PYTHONPATH. So, extend default_extend_env config with PYTHONPATH pointing it to IPython source folder.
There are 2 ways to make it, win10, conda python3.6.7, Ipython7.1.1, Sublime 3.1.1
1.Open \Packages\SublimeREPL\config\Python\Main.sublime-menu, find the line
"windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
and change it to where your ipython.exe located, for me is
"windows": ["C:\\Python\\envs\\py37\\Scripts\\ipython.exe"]
2.Just modified \Packages\SublimeREPL\config\Python\ipy_repl.py to 3 lines,
import os
# change dir to path_to_ipython.exe
os.chdir(r'C:\Python\envs\py37\Scripts')
os.system('ipython')
I prefer the second one, if you encount problems with first way, such as your shortcut about sublimeREPL not work (happens to me:(), try second one.

Keybinding for SublimeREPL to launch a Python virtualenv

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"],

Categories

Resources