Vscode Code Runner Python

In this post we'll look at how to develop in Python using Visual Studio Code. I'll also show you a few extensions that can make your life much easier while working with Python!

Initial setup

Local computer: switch to the Run view in VS Code, select the Python: Attach configuration. Local computer: set a breakpoint in the code where you want to start debugging. Local computer: start the VS Code debugger using the modified Python: Attach configuration and the Start Debugging button. VS Code should stop on your locally set breakpoints, allowing you to step through the. Python debugging in VS Code. The Python extension supports debugging of several types of Python applications. For a short walkthrough of basic debugging, see Tutorial - Configure and run the debugger. Also see the Flask tutorial. Both tutorials demonstrate core skills like setting breakpoints and stepping through code. I have already talked about the remote-ssh VSCode extension that changed my way to code in Python for small electronics projects with a Raspberry Pi.Here we'll take a look at an extension that makes it a lot easier to develop inside a container. 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.

When you install Python (which I recommend you do via the official installer), remember in which folder it was installed. And on Windows, make sure to tick the 'Add Python to PATH' in the first screen of the official installer.

Download Visual Studio Code and install it like you would any other application.

Open Visual Studio Code and navigate to the Extensions panel on the left hand side. There, look for the Python extension and install it

Once that's installed, you can open any folder using Visual Studio Code and create a file that ends in .py. The Python extension will use appropriate syntax highlighting and also help you code by offering you suggestions and hints.

You can change which version of Python the extension uses by clicking on the bottom left, where in the screenshot it says 'Python 3.7.4 32-bit'. This will let you select a different version from those you have already installed. Note that if you only have one version, you'll only be able to select that.

Here's a link to the Python extension: https://marketplace.visualstudio.com/items?itemName=ms-python.python

Vscode Code Runner Python

The Code Runner extension

Another extension, aptly called 'Code Runner', allows you to run your code more easily than normal. It gives VSCode a 'Play' icon at the top right, and when you click it, the selected code will run.

This is great because it allows you to either:

  • Select a portion of your code and run it, for example if you want to double-check what it does;
  • De-select all your code and just open a file, and press the 'Play' icon to run the entire file.

C Programming In Vs Code

Do note that if you select only a portion of the code and run it, this portion cannot depend on variables or functions defined elsewhere in the code.

Link: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

Code

The indent-rainbow extension

An extension called 'indent-rainbow' will color every indentation level in Python in a slightly different color, so you can very easily tell which parts of your code are at which indentation level.

This is what the extension will do:

Link: https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow

The Rainbow Brackets extension

If you like the indent-rainbow extension, you might also like Rainbow Brackets extension, which highlights nested parentheses, square brackets, and curly braces in different colours, making it easier to keep track of nested brackets.

Link: https://marketplace.visualstudio.com/items?itemName=2gua.rainbow-brackets#overview

The vscode-icons extension

While this extension is by no means required to run Python code, I use it and like it very much as it allows me to more easily scan my open files and folders by giving them nicer icons.

You can install this in order to change the icons displayed beside files and folders in your currently open project.

Vscode Code Runner Python

Link: https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons

Python

Java Code Runner

Conclusion

Vscode Code Runner Python3

That's it! As long as your Python version is in your PATH (which happens automatically on Mac and Linux, and you must tick the box in the installer in Windows), the Python extension will straight work out of the box!

If you have persistent issues, Google is your best friend as tens of thousands of people use this extension, and almost all potential problems have already been discussed and solved in other occasions. The development team is also very helpful in their GitHub page.

The GitHub page also contains extensive guides and information on how to get the extension up and running, it case it's necessary!

Hope this has been helpful and your environment is now all set up. Happy coding!