Previously, when we used the 'Code Runner' extension, the run button 'Run Code' provided by it would overwrite the 'Run Python File in Terminal' button provided by the 'Python' extension. But now, these two buttons are integrated, which allows us to choose two different ways of performing the display: in ' OUTPUT ' or ' Terminal '. Build, Run & Share Python code online using online-python's IDE for free. It's one of the quick, robust, powerful online compilers for python language. Don't worry about setting up python environment in your local. Now Run the python code in your favorite browser instantly. Getting started with this Python editor is easy and fast. Build, Run & Share Python code online using online-python's IDE for free. It's one of the quick, robust, powerful online compilers for python language. Don't worry about setting up python environment in your local. Now Run the python code in your favorite browser instantly. Getting started with this Python editor is easy and fast.
Run code snippet or code file for multiple languages: C, C++, Java, JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, F# (.NET Core), C# Script, C# (.NET Core), VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script, R, AppleScript, Elixir, Visual Basic .NET, Clojure, Haxe, Objective-C, Rust, Racket, Scheme, AutoHotkey, AutoIt, Kotlin, Dart, Free Pascal, Haskell, Nim, D, Lisp, Kit, V, SCSS, Sass, CUDA, Less, Fortran, and custom command
Sponsors
Increase your coding productivity with Tabnine’s AI code completions! Tabnine is a free powerful Artificial Intelligence assistant designed to help you code faster, reduce mistakes, and discover best coding practices - without ever leaving the comfort of VS Code.
Tabnine is trusted by more than a million developers worldwide. Get it now.
Eliminate context switching and costly distractions. Create and merge PRs and perform code reviews from inside your IDE while using jump-to-definition, your keybindings, and other IDE favorites. Learn more.
Track and prioritise tech debt and maintenance issues, straight from your IDE. Bookmark code while you work, organise TODOs and share codebase knowledge with your team. Try it out for free today.
Book for VS Code
《Visual Studio Code 权威指南》:带你深入浅出 VS Code!
WeChat Official Account
VS Code 的热门文章、使用技巧、插件推荐、插件开发攻略等,请关注“玩转VS Code”公众号!
Donation
If you like this extension, you could become a backer or sponsor via Patreon, donate via PayPal, or scan below QR code to donate via Alipay. Any amount is welcome. It will encourage me to make this extension better and better!
Features
- Run code file of current active Text Editor
- Run code file through context menu of file explorer
- Run selected code snippet in Text Editor
- Run code per Shebang
- Run code per filename glob
- Run custom command
- Stop code running
- View output in Output Window
- Set default language to run
- Select language to run
- Support REPL by running code in Integrated Terminal
Usages
- To run code:
- use shortcut
Ctrl+Alt+N
- or press
F1
and then select/typeRun Code
, - or right click the Text Editor and then click
Run Code
in editor context menu - or click
Run Code
button in editor title menu - or click
Run Code
button in context menu of file explorer
- use shortcut
- To stop the running code:
- use shortcut
Ctrl+Alt+M
- or press
F1
and then select/typeStop Code Run
- or click
Stop Code Run
button in editor title menu - or right click the Output Channel and then click
Stop Code Run
in context menu
- use shortcut
- To select language to run, use shortcut
Ctrl+Alt+J
, or pressF1
and then select/typeRun By Language
, then type or select the language to run: e.gphp, javascript, bat, shellscript...
- To run custom command, then use shortcut
Ctrl+Alt+K
, or pressF1
and then select/typeRun Custom Command
Configuration
Make sure the executor PATH of each language is set in the environment variable.You could also add entry into code-runner.executorMap
to set the executor PATH.e.g. To set the executor PATH for ruby, php and html:
Supported customized parameters
- $workspaceRoot: The path of the folder opened in VS Code
- $dir: The directory of the code file being run
- $dirWithoutTrailingSlash: The directory of the code file being run without a trailing slash
- $fullFileName: The full name of the code file being run
- $fileName: The base name of the code file being run, that is the file without the directory
- $fileNameWithoutExt: The base name of the code file being run without its extension
- $driveLetter: The drive letter of the code file being run (Windows only)
- $pythonPath: The path of Python interpreter (set by
Python: Select Interpreter
command)
Please take care of the back slash and the space in file path of the executor
- Back slash: please use
- If there ares spaces in file path, please use
'
to surround your file path
You could set the executor per filename glob:
Besides, you could set the default language to run:
For the default language: It should be set with language id defined in VS Code. The languages you could set are java, c, cpp, javascript, php, python, perl, ruby, go, lua, groovy, powershell, bat, shellscript, fsharp, csharp, vbscript, typescript, coffeescript, swift, r, clojure, haxe, objective-c, rust, racket, ahk, autoit, kotlin, dart, pascal, haskell, nim, d, lisp
Also, you could set the executor per file extension:
To set the custom command to run:
To set the the working directory:
To set whether to clear previous output before each run (default is false):
To set whether to save all files before running (default is false):
To set whether to save the current file before running (default is false):
To set whether to show extra execution message like [Running] ... and [Done] ... (default is true):
[REPL support] To set whether to run code in Integrated Terminal (only support to run whole file in Integrated Terminal, neither untitled file nor code snippet) (default is false):
To set whether to preserve focus on code editor after code run is triggered (default is true, the code editor will keep focus; when it is false, Terminal or Output Channel will take focus):
code-runner.ignoreSelection
: Whether to ignore selection to always run entire file. (Default is false)
code-runner.showRunIconInEditorTitleMenu
: Whether to show 'Run Code' icon in editor title menu. (Default is true)
code-runner.showRunCommandInEditorContextMenu
: Whether to show 'Run Code' command in editor context menu. (Default is true)
code-runner.showRunCommandInExplorerContextMenu
: Whether to show 'Run Code' command in explorer context menu. (Default is true)
code-runner.showStopIconInEditorTitleMenu
: Whether to show 'Stop Code Run' icon in editor title menu when code is running. (Default is true)
code-runner.terminalRoot
: For Windows system, replaces the Windows style drive letter in the command with a Unix style root when using a custom shell as the terminal, like Bash or Cgywin. Example: Setting this to /mnt/
will replace C:path
with /mnt/c/path
(Default is ')
code-runner.temporaryFileName
: Temporary file name used in running selected code snippet. When it is set as empty, the file name will be random. (Default is 'tempCodeRunnerFile')
code-runner.respectShebang
: Whether to respect Shebang to run code. (Default is true)
About CWD Setting (current working directory)
- By default, use the
code-runner.cwd
setting - If
code-runner.cwd
is not set andcode-runner.fileDirectoryAsCwd
istrue
, use the directory of the file to be executed - If
code-runner.cwd
is not set andcode-runner.fileDirectoryAsCwd
isfalse
, use the path of root folder that is open in VS Code - If no folder is open, use the os temp folder
Note
- For Objective-C, it is only supported on macOS
- To run C# script, you need to install scriptcs
- To run TypeScript, you need to install ts-node
- To run Clojure, you need to install Leiningen and lein-exec
Telemetry data
By default, telemetry data collection is turned on to understand user behavior to improve this extension. To disable it, update the settings.json as below:
Change Log
See Change Log here
Issues
Submit the issues if you find any bug or have any suggestion.
Contribution
Fork the repo and submit pull requests.
- Trending Categories
- Selected Reading
After writing the code, we need to run the code to execute and obtain the output. On running the program, we can check whether the code is written is correct and produces the desired output.
Running a python program is quite an easy task.
Run on IDLE
To run a python program on IDLE, follow the given steps −
Code-runner.executormap Python
Write the python code and save it.
To run the program, go to Run > Run Module or simply click F5.
Run on Command Line
The python script file is saved with ‘.py’ extension. After saving the python script, we can run it from the Command Line. In the cmd, type keyword ‘python’ followed by the name of the file with which you saved the python script.
Example
Let us suppose, we have a python script saved with the name ‘hello.py’. To run it on command line, type the following −
Run On IDE (PyCharm)
To run a python program on an IDE like PyCharm, we need to follow the given steps −
Create a new python file and save it with some name, say “hello.py”.You don’t need to specify the extension as it will pick it automatically.
After writing the required code in the python file, we need to run it.
To run, Click on the Green Play Button at the top right corner of the IDE. The second way to run is, Right click and select ‘Run File in Python Console’ option.
This will open a console box at the bottom and output will be shown there.
Interactive Mode
Interactive mode is the method to type and run python code in command line. In interactive mode, the python code is written and run line by line in a sequential manner.To enter into interactive mode, open Command Prompt and type ‘python’ and press Enter.
Write one line of code and press enter to execute it and enter the second line.
How To Run Python Code
Example
To run the code in interactive mode, You must have python installed on your system. On typing ‘python’ , the version of the python installed on your system is displayed. This means that python is installed on your system and we can move forward in running python scripts. On entering one line of code i.e. print(“Hello World”) ,after pressing enter the “Hello World” is displayed.
Run on Text Editor(Visual Studio)
Idle Python Download
We can run python script on a text editor. To do so,follow the following steps −
Create a file with a name ,let “hello.py”.
Write some python code in the file.
To run the code, Right Click > Select Run Code. Else, press ‘Ctrl+Alt+N’ to run the code.
Run Python Script In Python
- Related Questions & Answers