Run Python Visual Studio Code

Posted on  by 



Visual Studio Code Run Python File, Python Run in Visual Studio code, Python File Run in Visual Studio Code or VS Code.Pylint install Using Line in Command. There isn’t much support for Python in Microsoft new code editor Visual Studio Code (VSCode), but there is a neat way to run your Python code right inside VSCode. It’s a feature called tasks and while the examples give are for compiling code, you can pretty much just run any program against the code you are editing in VSCode. Visual Studio warns you if you still have errors in your code. When you run the program, a console window appears displaying the results, just as if you'd run a Python interpreter with PythonApplication1.py from the command line. Press a key to close the window and return to the Visual Studio.

Run Python Script Vs Code

There isn’t much support for Python in Microsoft new code editor Visual Studio Code (VSCode), but there is a neat way to run your Python code right inside VSCode. It’s a feature called tasks and while the examples give are for compiling code, you can pretty much just run any program against the code you are editing in VSCode.

Tasks

So let’s dive in and set-up a task that runs the traditional 'Hello World!' program within VSCode. In Python this is print 'Hello World!'.

First go and open up VSCode on an empty folder via the menu steps File -> Open Folder. The do Ctrl+Shift+P, then Configure Task and press Enter. This will create a folder called .settings and a file called tasks.json where you will configure your task. Comment out the first example task and put the following Python task at the top of the file and save it.

To run the task you can simply do Ctrl+Shift+B, as you’ve only defined one task for this folder. If you put another task at the top of the settings file then that task will be run. If you need to select a task do Ctrl+Shift+P, type Run Tasks, select python and press Enter.

Visual studio won

You can find out more about tasks in VSCode here.

Run Python On Visual Studio Code

Result

Visual Studio Code Python Tutorial

Run python in visual studio code

Create Python Script In Visual Studio Code

The result of all this is that you now can run a python script and have the output displayed next to the code, as shown below.

Run Python Tests In Visual Studio Code

I’ve only played with VSCode for a little while, but it seems solid and friendly. Hopefully support for more languages will be coming soon, but at least you can run any compiler or interpreter against your code using tasks.





Coments are closed