Python Programming Made Easy: A Simple Guide to Setting Up VS Code

Ali Tahir
4 min readFeb 25, 2023

--

Visual Studio Code (VS Code) is a popular and powerful code editor that can be customized to suit your specific programming needs. If you are a Python programmer, you can use VS Code to create and manage Python projects. In this article, we will show you how to set up VS Code for Python with auto-formatting and Python main extensions support.

Step 1: Install Python and VS Code Before setting up VS Code for Python, you need to install Python on your computer. You can download and install the latest version of Python for windows from the official website (https://www.python.org/downloads/).

Once you have installed Python, download and install the latest version of Visual Studio Code for windows from the official website (https://code.visualstudio.com/).

To install Python on Ubuntu, open a terminal window and run the following command:

sudo apt-get install python3

This will install the latest version of Python 3. To install VS Code, go to the official website (https://code.visualstudio.com/Download) and download the appropriate .deb package for Ubuntu.

Once the download is complete, open a terminal window and navigate to the directory where the .deb package was downloaded. Then, run the following command to install VS Code:

sudo apt install ./<file_name>.deb

Step 2: Install Python Extensions To work with Python in VS Code, you need to install the following extensions:

  • Python
  • Pylance

To install these extensions, open VS Code and click on the Extensions icon on the left-hand side of the window. In the search bar, type “Python” and click on the “Install” button next to the “Python” extension. Once the installation is complete, repeat the same process for the “Pylance” extension.

Step 3: Configure Python Path After installing the Python and Pylance extensions, you need to configure the Python path in VS Code. This is necessary for VS Code to be able to find and use the Python interpreter.

To configure the Python path, open the VS Code settings (Ctrl+,) and search for “python.pythonPath”. Click on the “Edit in settings.json” button and add the path to your Python installation in the JSON file, like this:

# Windows
"python.pythonPath": "C:\\Python39\\python.exe"

# Ubuntu
"python.pythonPath": "/usr/bin/python3"

Step 4: Configure Auto-Formatting Auto-formatting is a great feature that saves you time and ensures consistency in your code. To configure auto-formatting in VS Code, you need to install the following extension:

  • Python — Formatting

To install this extension, open VS Code and click on the Extensions icon on the left-hand side of the window. In the search bar, type “Python — Formatting” and click on the “Install” button next to the extension.

Once the extension is installed, you can configure it by opening the VS Code settings (Ctrl+,) and searching for “python.formatting.provider”. Select “autopep8” as the value for this setting. You can also configure other auto-formatting settings in this section.

Step 5: Create a Python Project After setting up VS Code for Python, you can create a new Python project by clicking on the “Explorer” icon on the left-hand side of the window and selecting “New Folder”. Give your project a name and open the new folder in VS Code.

To create a new Python file in your project, right-click on the folder and select “New File”. Give the file a name with a .py extension, for example “hello_world.py”. You can now start writing your Python code in this file.

Step 6: Run and Debug Your Python Code To run and debug your Python code in VS Code, you can use the built-in debugging tools. To start debugging, click on the “Run and Debug” icon on the left-hand side of the window and select “Add Configuration”. Select “Python” as the environment and VS Code will generate a launch.json file in your project folder.

You can now run your Python code by clicking on the “Run” button in the top toolbar. You can also set breakpoints in your code and use the debugging tools to step through your code line by line.

In conclusion, setting up VS Code for Python with auto-formatting and Python main extensions support can make your life as a Python programmer much easier. With the right tools, you can write clean, consistent code and debug your programs with ease.

But let’s be real, setting up a new development environment can be a pain in the neck. It’s like trying to assemble a new piece of furniture with instructions written in a foreign language. But fear not! By following these simple steps, you’ll be up and running in no time.

And who knows, maybe you’ll even enjoy setting up your new development environment. It’s like getting a new toy to play with, except instead of a toy, it’s a powerful code editor. Okay, maybe it’s not exactly like getting a new toy, but you get the idea.

So go forth, my fellow Python programmers, and set up your VS Code environment with confidence! And if you get stuck, remember that there are plenty of resources out there to help you along the way. Happy coding!

--

--

Ali Tahir

Experienced Python Developer with expertise in Full-stack, Data Analysis, Web Scraping & Computer Vision. Passionate prob-solver. linkedin.com/in/ali-tahir1010/