Python With Visual Studio Code



Afterwards, open Visual Studio Code and left-click on the Visual Studio Code interpreter shown in Visual Studio Code at the bottom left: Choose a virtual environment that pops up in a dropdown of the settings window, and you are done. Mind the answer of @RamiMa. But regardless enjoy this code as it will likely no longer be valid from Python 3.10 onward. Edit: Edited printing out the annotations dictionary, as I can just print annotations directly and don't need to look it up in locals. Given I'm ignoring VS Code for the main code example I'm not sure why I listened to it complaining here.

Standard plot

  • Paste the following code in a python file
  • Execute it (either selecting the code or using the Run cell code lens).
  • The result is a static graph displayed in the Results window

Interactive Plot using D3js

  • Paste the following code in a python file
  • Execute it (either selecting the code or using the Run cell code lens).
  • The result is an interactive displayed in the Results window
  • Check here for more infor on D3js

Note: Hover the mouse over the graph and a toolbar should appear allowing you to interact with the graph

Interactive Plot using Bokeh

  • Paste the following code in a python file
  • Execute it (either selecting the code or using the Run cell code lens).
  • The result is an interactive displayed in the Results window
  • Check here for more info on Bokeh graphs

Note: Use the toolbar next to the graph image, to interact with the graph.

LaTeX

Set up python with visual studio code
  • Check here for more info on LaTeX

Inline images

Python visual studio code venv

IFrame

More examples

  • Interactive Matplotlib graphs using d3js (mpld3)
  • Interactive Bokeh graphs

To comment out a line of code in Python, you can add a # before that line. So how to comment out a block of code in Python? If you have worked with some other programming language like Javascript, Dart … then you will be familiar with / * * / syntax. However, you cannot do that in Python.

To comment on a block of code in Python, you will have to prefix it with # line by line. If a block of code had hundreds of lines, it would be terrible.

Visual

Solution

Fortunately, if you use Visual Studio Code, commenting a block of code is really quick and easy. All you need to do is select that code block with your mouse, then press the following key combination:

Python With Visual Studio Code

  • Ctrl + K then press Ctrl + C if you’re using Windows
  • Command + K then press Command + C if you’re on a Mac

To uncomment a block of code, use your mouse to select it and then use the key combination:

With
  • Ctrl + K then Ctrl + U if you’re on Windows
  • Command + K then Command + U if you’re on a Mac

Microsoft Visual Studio Code Python

A Small Trick

If you don’t like the mentioned solution above, you can use the triple-quote trick to make a block of Python code not run. This action doesn’t actually comment out anything but only converts the code between the triple-quotes to a string.

Example:

Python With Visual Studio Code

The syntax for triple quotes consists of three consecutive single or double-quotes.

Python’s triple quotes come to the rescue by allowing strings to span multiple lines, including verbatim NEWLINEs, TABs, and any other special characters.

Python With Visual Studio Code Tutorial

What Next?

Learn Python With Visual Studio Code

Hopefully, this article has made working with Python a little easier and more comfortable. If you’d like to learn more about Python, check out our Python category page for the newest tutorials and examples.

Visual Python Ide

Related Articles