Python + VS Code Installation and Setup Guide (Windows) — 2

Ran
Ran

Table of Contents

Python and Visual Studio Code

Last Article:

Python + VS Code Installation and Setup Guide (Windows) — 1

Notes before Start:

These 2 articles are about installing and setting up Python and Visual Studio Code on Windows.

  • By the end of the last article, you should be able to run simple python code on both Command Prompt and Python IDLE.
  • By the end of this article, you should be able to run a simple Python program on VS code.
  • The instructions should work for any version of Python and VS Code.
  • You can always skip the Explanations and “Q(Questions)” sections in this article.

The instructions should work for any version of Python and VS Code.

Some related questions answered in this article:

  • What are the differences between VS Code’s stable and insider version?
  • What if you cannot see PowerShell in the terminal?
  • What are the 2 basic methods to run a Python program in VS Code?
  • What are the differences between these 2 methods?

Download and Install Visual Studio Code

  1. Go to the website: https://code.visualstudio.com/. Click the dropdown menu. Download the Stable version of VS Code.
Download Visual Studio Code

Q: Stable v.s. Insiders

  • Insiders: prerelease versions, contains new features, but not stable
  • Stable: stable
  • Can be installed together and used simultaneously

2. Accept and click “Next.

License Agreement for installing Visual Studio Code

3. Click “Next.

Destination Location for Visual Studio Code

4. Click “Next.”

Stat Menu Folder for Visual Studio Code

5. Check “Create a desktop icon” and click “Next.

Select Additional Tasks for Visual Studio Code

6. Click “Install.

Click install for Visual Studio Code

7. Click “Finish.

Click finish and launch visual studio code

8. Launch VS Code. At this point, your VS Code is installed successfully. (Just close the lower right corner message here)

Launch Visual Studio Code

Set up VS Code and Python

How to make it look bigger

  • Click “View” → “Appearance” → “Zoom In
  • Or press “Ctrl” + “=
  • Ctrl” + “-” for “Zoom Out
How to Zoom in and Zoom out for Visual Studio Code (Make the fonts larger or smaller)

Set up Python

  1. Click “Extensions” on the left.
Check extensions for visual studio code

2. Search “python” and click the first one.

Install python extensions for visual studio code

3. Click “Install.

Install python extension for visual studio code

Q: What are VS Code Extensions?

VS Code extensions let you add languages, debuggers, and tools to your installation to support your development workflow. VS Code’s rich extensibility model lets extension authors plug directly into the VS Code UI and contribute functionality through the same APIs used by VS Code.
Source

4. You can now close the pop-ups on the right (if any). Then, you can click the “Explorer” on the left.

Click the explorer in visual studio code

If this shows up, just click “Do not show again.”

Click “do not show again” for linter pylint

5. Click “File” → “Open Folder” (Ctrl+K Ctrl+O)

Open folder in visual studio code

6. Choose a folder that you would like to put your python code and click “Select Folder.

Select folder for visual studio code

7. We can see that the folder name is shown here. Then we can click the first logo for “New File” and name the file “start.py” (or whatever you like).

Open a new file under a folder in visual studio code

8. Write a simple python program.

Write a simple python program in visual studio code

9. Open the terminal section in VS Code. Click “View” → “Terminal” (Or Ctrl + `)

How to open terminal in visual studio code

10. You should see PowerShell if you did not install something like git before.

If you did not see PowerShell:

Click here and choose “Select Default Shell,” and then choose “Windows PowerShell.

What to do if you did not see powershell in the visual studio code’s terminal

11. Click “Kill Terminal” and then open Terminal again (View →Terminal). You should see “powershell” then.

Kill terminal and open terminal again

Now there are 2 ways to run a Python program in VS Code:

1st method:

Type “python start.py” in the terminal. This is the same as what was mentioned in the last article.

run python code in visual studio code by using “python”

2nd method:

Click “Run python file in terminal”

Right-click and select “Run Python File in Terminal.

Run python file in visual studio code by the full path of python and your file

This shows the full path of both Python and your program. The path should be the same as what we mentioned in the last article.

Difference Between These 2 Methods

They are almost the same. But there is one difference.

The 1st method is directly related to the path, while the 2nd method is not.

For example, if I changed the “python.exe” to “python2.exe” in the path.

(Read the first article if don’t understand what path is here.)

change the name of python exe file in the path

The 1st method will work if you typed “python2 start.py”:

run a python program after changing the name of the python exe file in the path

The 2nd method will get error messages.

Error messages: The term is not recognized as the name of a cmdlet, function, script file

Because the 2nd method is not directly related to the path, the VS Code actually saved the path information when you start VS Code.

In order to make the 2nd method work as well, you can press “Ctrl+Shift+p” to open the Command Palette.

How to open command palette in visual studio code

Then type “reload window” and press Enter.

How to reload window in visual studio code

Then you can click “Select Python Interpreter” in the lower-left corner. You should see the new “python2” showing in the middle. Select it, and then you can use the 2nd method.

Select python interpreter

However, if you changed the name in the path to “pyt” (not even containing the string “python”), this “reload window” method does not work as well, so I think VS Code uses the “python” string to be the selecting criteria.

By now, you should know how to run a python program in VS Code. You may see other people use the extension “Code Runner” to run the Python program in VS Code, but I don’t use it here because I think it is better to know the basic methods before moving to more advanced tools.

I hope this article helps you!

(Support me by a coffee monthly or becoming a member. 😊😊)

PythonVSCodeSetup Guide

Ran

Comments