Beginning your Python journey can be very exciting, especially if you’ve never installed an IDE before. The process is quite simple and doesn’t take much time to complete. In this guide, we will walk you through installing Visual Studio Code and the required extension for Python development. We also outline how to enter code, save files, and run programs.
Installing and Configuring Visual Studio Code for Python
You may have heard of the Microsoft Visual Studio, but VS Code shares nothing with that tool other than the name. You can write programs in multiple languages in VS Code thanks to its built-in support for extensions. VS Code is available on Windows, Mac, and Linux, and the IDE is updated monthly. To install the program on your operating system, visit the official website and find the stable version of the tool by hovering your mouse over the arrow on the download button. On Windows, running the installer and following the setup instructions will complete the installation. On Mac, you will need to drag the downloaded “Visual Studio Code.app” file to your applications folder. To install VS Code on a Ubuntu or Debian machine, you can run the following command in the terminal: sudo apt install ./<file>.deb
The VS Code Python Extension
To enable VS Code to work with your programming language of choice, you will need to install the relevant extension. Installing the Python extension unlocks the following features in VS Code:
- Automatic conda use and virtual environments
- Code completion with IntelliSense
- Code editing in Jupyter environments and Jupyter Notebooks
- Code snippets
- Debugging support
- Linting
- Support for Python 3.4 and higher, as well as Python 2.7
- Unit testing support
To install the extension, press Ctrl+Shift+X to open up the Extensions view. You can also do this by clicking the Extensions icon on the activity bar. Search “Python” and hit the install button to install the extension right from the VS Code Marketplace. You can also find the extension on the marketplace here.
Writing and Running a Python Program in VS Code
Open a new file by clicking File on the top bar and then clicking New. A keyboard shortcut you can use instead is Ctrl+N. You can now start entering the code in the new file. But it’s important to note that VS Code will not recognize the language you are writing the code in. This is because it doesn’t know what the file type is. You can activate the Python extension by saving the file. The Save option is available in the File menu, but you can use Ctrl+S. Once the .py extension is attached to the file, VS Code will recognize your code. After entering your code, you can run it by right-clicking inside the code editor window and clicking “Run Python File in Terminal.” The terminal will appear at the bottom of the screen with the output of your program.