Visual Studio Code or VS Code is Microsoft’s flagship code editor that works across Windows, Mac OS, and Linux platforms. Furthermore, it comes for free. It is one of the widely used code editors and IDEs because of its robust set of features.
Can You Code Python In VS Code?
Yes! VS Code can be configured for coding Python. Furthermore, it provides a new experience wherein you can use the full power of VS Code in the Python environment while switching between Virtual and Conda environments.
How Do I Setup VS Code For Python?
To set up VS Code for Python, here are a few things you’ll need to install on your system so that you’re able to write code, debug it and run it in VS Code.
Python Interpreter (Latest Version)
To write, debug and run a Python program, you need to set up a Python run-time environment. For this, you’ll need to first download and install Python on your system.
You can install Python on all three operating systems – Linux, Mac OS, and Windows. For this example, we’re going to show you how to do it on Windows.
Go to https://www.python.org/downloads/ to download and install Python.
Once you do, you’ll need to check if you’ve installed it right. So open your command prompt and check the version of Python you have installed. If the version number appears, it means that you’ve installed it correctly.
VS Code Python Extension
Considering you’ve already downloaded and installed VS Code on your system, you can now download the Python Extension for the VS Code.
The purpose of installing a Python extension is to create a Python environment within the code editor. Without that, you will be able to write the Python code on the software, but it will not understand or interpret the code.
So there are two ways in which you can download and add the extension to VS Code:
- Go to Visual Studio marketplace and download it
- In VS Code, search for Python in extensions search bar and install it
The first method is that you go to the link below: https://marketplace.visualstudio.com/items?itemName=ms-python.python
From here, you can simply click the install button, follow the instructions and download the Python extension.
The second method is relatively simple. Here, just open your VS Code environment, and on the left side, there’ll be an icon for Extensions. Click on it, type Python in the search bar that appears, and install the extension.
Gather extension for VS Code will automatically analyze the code dependencies within a notebook and perform the cleanup.
The Live Share extension for VS Code will allow you to collaborate with other people and work together on the code.
A few more packages that you will find helpful while coding Python are given below.
This allows you to perform data cleaning and transformation, numerical evaluation, create statistical models, use it for machine learning, and more.
This is used for performing scientific computations in Python. It has got multidimensional array objects, matrices that can be used for various purposes.
This is one of the most widely used packages for machine learning. It has tools for performing clustering, regression, classification, and more.
Although you can run your code files outside VS Code, it is better to have the Code Runner extension since it helps you run code files or active code text directly on the VS Code editor.
You can search for the Code Runner extension in VS Code and install it as shown in the screenshot above.
Running a Python Script inside VS Code
- Create a file called hello.py
- Type the code print (“Hello World”)
- Save the file
- Press Ctrl + Alt + N or click the Play button on the top right corner to run the file.
- You can then press Ctrl + Alt + M to stop running the code.
- Alternatively, you can also press F1 and select Run Code to run your code file.
How To Change Python Version In VS Code?
- Go to the View menu and select Show Command Palette.
- From here, choose Select: Python Interpreter.
- You see the various versions/interpreters on your system, and selecting one will add an entry to python.pythonpath.
Yes, by far, it is one of the best IDE’s out there, if not the best! Once you install the Python Extension and a few other packages, you can use VS Code’s full power to build your projects/programs.
The three primary advantages are:
- Code writing becomes much easier due to its robust features.
- Its speed and performance are impeccable.
- You only need to download limited packages to fulfill your requirements.
- It becomes a one-stop-shop for all the things you need to develop a full-fledged program.
Overall, as an IDE VS Code is much better than PyCharm for the following reasons:
- VS Code as software is much more lightweight when compared to PyCharm.
- VS Code’s performance trumps PyCharm by a large margin since it uses a modular approach and uses only the necessary resources.
- The general resource management is more efficient in VS Code since PyCharm is infamous for hogging too much memory and RAM while being used.
All in all, VS Code is a clear winner because of the factors mentioned above.
Want More Tips and Tricks? Subscribe to our Newsletter!
If you haven’t already subscribed, please subscribe to The Productive Engineer newsletter. It is filled with tips and tricks on how to get the most out of the productivity apps you use every day. We hate spam as much as you do and promise only to send you stuff we think will help you get things done.