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

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.

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.

3. Click “Next.

4. Click “Next.”

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

6. Click “Install.

7. Click “Finish.

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

Set up VS Code and Python

How to make it look bigger

  • Click “View” → “Appearance” → “Zoom In
  • Or press “Ctrl” + “=
  • Ctrl” + “-” for “Zoom Out

Set up Python

  1. Click “Extensions” on the left.

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

3. Click “Install.

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.

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

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

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

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).

8. Write a simple python program.

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

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.

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

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.

2nd method:

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

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.)

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

The 2nd method will get error messages.

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.

Then type “reload window” and press Enter.

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.

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. 😊😊)