Writing in python on VS Code
Hi! Let’s take a look at how to start coding in python with Visual Studio Code.
Installing VS Code
First, to install Visual Studio Code in Ubuntu I used these commands:
curl https://packages.microsoft.com/keys/microsoft.asc | gpg — dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo apt-get update
sudo apt-get install code
Otherwise, there is the official website where to download it from.
Installing Python
In most Linux distros python is already installed, so no big worries there. If you are on Windows there is a download page on python.org. Alternatively, writing “python” in Command Prompt will open the Microsoft Store to the last version of Python.
To check the installation worked and Python is working run the commands below. If the installation was successful, the output should be the version of Python you installed, e.g. “Python 3.8.5”.
Linux:
python --version
Windows:
py -3 --version
My current setup is Pop!_OS 20.04 LTS with Python 3.8.5. I am going to create a new folder on the Desktop where to work:
mkdir ~/Desktop/playground
cd ~/Desktop/playground
Then I can open VS Code in this folder:
code .
You can see on the left that we are in the playground folder, which is empty for now.

On the left, there is a column of symbols. Press on the last one, the one with the squares, “Extensions”, and search for the Python Extension and install it. It is required to run Python code.

Python needs an interpreter to be executed. This interpreter, in your system, is a file, and there can be more than one, one for every different version of Python you have installed, for example. VS Code needs to know what interpreter use, so we must tell him. Press Ctrl + Shift + P to open the Command Palette.

Then type Python: Select Interpreter.

This will show the different interpreters that VS Code automatically detects on your system. Select the one you want.
Now in the low-left corner, there should be indicated the python interpreter. This means that VS code knows that he must use the interpreter of that version. We are good to go!
Going over “Playground” will appear some buttons. Click the one on the left, “New File”, and name the new file “hi.py”.
On the right, let’s write the code below and press Ctrl + S to save it.
print(“Hi, world!”)
In the high-right corner, there is a green play button. Pressing it will cause VS code to open a new tab in the lower side of the window, a terminal, where the code is executed and the output is shown.

Our program has been executed!
There are still a lot of things to do. To work properly in python we need to set up a virtual environment for our workspace and get some vs code extensions. But that’s for another day.
I hope that this little guide helped you!
Have a good day!