0

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?

Ach113
  • 1,775
  • 3
  • 18
  • 40
  • If you are using Windows, you can simply use the Command Prompt, first by entering the folder where your .py is located: cd . Assuming you have one python version installed, you can then type in python filename.py . If you are on Linux, python will come preinstalled. Open the terminal, enter the directory of your file: cd . The if you are using Python 3, type in python3 filename.py, if you are using Python 2, type in python filename.py . Hope it helps :) – Mahir Islam Jul 22 '18 at 06:03
  • Does your program terminate ? Or does it run a loop ? – Flint Jul 22 '18 at 06:22
  • @Flint the programs compile just fine, but in IDLE, i was capable of doing additional operations in shell after program was executed, like checking what values certain variables hold etc. But with ***repl closed*** I cannot do that – Ach113 Jul 22 '18 at 06:39
  • a python code can be loaded from a running program, that's why I asked if the program did terminate. In a interactive mode, with, say, a rendering thread, it's perfectly possible to interact with a running program and enter commands to modify some values on the fly. Of course that good IDLE keeps the interpreter open, since it continues to run IDLE itself. – Flint Jul 22 '18 at 11:47
  • Tried Jupyter or Ipython with %autoreload option ? – Flint Jul 22 '18 at 11:54

1 Answers1

1

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.

Flint
  • 1,651
  • 1
  • 19
  • 29