Alfie Stoppani
Alfie Stoppani

Reputation: 199

How can I create a build system in Sublime Text to run my python code in an IDLE shell?

How can I run my code from Sublime Text in an IDLE shell. I much prefer using IDLE to run my code when I'm writing it because it's really easy to debug. However I love Sublime Text and much prefer to actually write the script with it.

I'm trying to create a build system which runs my code with IDLE3.

However, when I do this, it simply opens an IDLE shell but doesn't run my file.

{
    "shell_cmd": "/Library/Frameworks/Python.framework/Versions/3.8/bin/idle3.8"
} 

And when I do this it opens my script with IDLE but doesn't run in the shell.

{
    "shell_cmd": ["/Library/Frameworks/Python.framework/Versions/3.8/bin/idle3.8","$file"]
} 

How can I get it to run the file in an IDLE shell?

Upvotes: 0

Views: 223

Answers (2)

PranDev
PranDev

Reputation: 11

Thanks for the question and the subsequent answer, simplified my search a lot.

A simple basic guide for anyone looking to do this in the future:

1. Create a build system

Go to Tools->Build System->New Build System... Enter the following:

{
    "cmd":["**PATH-TO idle file**", "-r","$file"],
    "selector": "source.python"  //Optional - Used when Tools | Build System | Automatic is set to true
}

In windows Path to Idle File for this is : "C:\\Program Files\\Python311\\Lib\\idlelib\\idle.bat" or something similar

2. Save the build system Save it as "*Your-Build-System-Name-Here*.sublime-build". It should normally get saved to ~\Sublime Text\Packages\User folder. Be careful about where you save, as SublimeText only checks for .sublime-build files in Packages folder for enumerating the build systems list

Your build system is ready. It should show up in the build systems list Tools->Build System with whatever you named the .sublime-build file. If it doesn't, close and reopen sublime text.

3. Test if it works

Open a simple python file with some code that has a print function like

for i in range(100):
    print i

and press Ctrl+B Your script should run in an IDLE window.

If that does nothing, press Ctrl+Shift+B, it should let you select your build system then run the code. If that also doesn't work, you can go to Tools-> Build System and change to your build system, and then do Ctrl+B

Optional Step

Building usually opens an output window. You can go to Preferences->Settings and add the line "show_panel_on_build": true,to disable it.

Be warned that this is an all-or-nothing step, it will turn off the output window for all build-systems. There currently isn't a way to set the option for a single build=sysem only as far as I know.

Upvotes: 0

Alfie Stoppani
Alfie Stoppani

Reputation: 199

I worked it out.

It's done like this:

{
    "cmd": ["/Library/Frameworks/Python.framework/Versions/3.8/bin/idle3", "-r", "$file"]
}

The example on the docs shows "-d" and it opens in debug mode so I had an educated guess and replaced it with "-r" which I guess means 'run'?

Upvotes: 1

Related Questions