fbpixel
Tags:

The VSCode code editor lets you create and develop projects in various programming languages, such as Python or C++, thanks to numerous extensions.

Installing VSCode

If you haven’t already done so, download and install VSCode

Using a code editor like VSCode is one of the best ways to increase the productivity of your Python projects.

You can install extensions such as Python or Python Debugger to help you with your programming.

vscode-python-extension Programming in Python with VSCode

Creating and configuring a Python project

To create a project, you can either navigate to a folder containing your projects and launch VSCode from that location in a terminal.

mkdir tuto
cd tuto
code .

Or open a folder from VSCode.

Using Command Palette, create a virtual environment that will allow you to keep a clean installation of Python and its packages for your project. Python : Create Environment … , select Venv then choose the desired Python version

Once the environment has been created, you can check the configuration of the environment interpreter. In the VSCode terminal, enter the following commands

python --version
python -m pip freeze

The pip freeze command should return an empty value, as there are no packages installed on a new virtual environment.

Create and run a Python script with VSCode

Then create a script.py file, with the code print(‘hello world’) which you can execute by right-clicking on the Run Python > Run Python File in Terminal edit page.

#! /user/bin/env python
# -*- coding: utf-8 -*-
"""
File: script.py
Author: Xukyo
email: email@email.com
Date:

Description: A simple Python script to print "Hello, world!"

Usage:
	python script.py 

Dependencies: None
Sources: www.aranacorp.com
"""

print("Hello world!")
vscode-python-run Programming in Python with VSCode

You can also use the Run > Start debugging menu (F5).

A terminal will open at the bottom of the window, reading Hello world!

Adding a Python library to VSCode

To install a Python library, simply run the following command in the VSCode terminal

python -m pip install <python_package>
#or
pip install <python_package>

You can then check your installation with the pip freeze command

Sources