Skip to main content
Version: 5.0

Python Development and Debugging on TorizonCore Using Visual Studio Code

Introduction​

This article explains how to run and debug Python Applications on TorizonCore using the Visual Studio Code extension provided by Toradex.

This article complies to the Typographic Conventions for Torizon Documentation.

Prerequisites​

Create a New Project​

Press F1 on Visual Studio Code and then type Torizon/Python: Create Python Application to create an application:

Creating a Python Application

You will be able to select a template. Some examples are a console or a Qt QML application.

After creating it, write the application name on the same command bar:

Naming your Python Project

Now you should be able to select an application template, this will pre-create all the files required for a specific kind of application.

A bunch of options will appear, make sure to select the right target architecture:

Selecting target architecture

info

For new projects we suggest choosing platforms based on debian bullseye, those are the platforms that will be maintained in the long term. Notice also that the list of platforms and templates may change after an update of the extension, providing new platforms for more recent versions of debian or templates for specific kinds of applications.

Type torizon on the username label:

Set Username

A python project with the following files will be created, to learn more about each one of them refer to the Python Project Configuration Files section.

Python project

Pylint warning

Pylint warning is not specific for Torizon, it will happen for any .py file. Although not mandatory, a linter is really helpful and recommended during development.

Set the Default Python Interpreter​

Some operating systems still point the python executable to Python 2, others may only use the python3 executable. You must make sure that Visual Studio Code is using a version of Python 3 as the default interpreter, otherwise, you may see an error message Path to shell executable "python" does not exist.

Press F1 and run the command Python: Select Interpreter:

Run "Python: Select Interpreter"

Select any version of Python 3:

Select a Version of Python 3

Configure Project​

Understand how to add Python packages and more in the next subsections.

Add Python Packages Available on Debian Feeds​

Open the Torizon configuration page and edit the extrapackages configuration, you just need to click on the pen icon:

Extra packages

As an example, add the package python3-pexpect:

Python3-pexpect package

This would be the equivalent of running apt install python3-pexpect on the command-line. It does not use pip.

Python Project Configuration Files​

The Torizon Extension for Visual Studio Code provides the following files for project configuration:

FileDescriptionExample Use Case
setup.shInstall additional components.Run apt-get install for Python libs that need native components.
requirements.txtPython packages to be installed via pip, one per line with optional versionPlease consider Add Python Packages Available on Debian Feeds as explained in the previous section.
This will simplify the management of binary components and ensure that the package version works with all the other libs provided in Debian.
Use pip only for packages that are pure Python code and are not available on Debian.
cleanup.shruns after pip has installed packages in requirements.txt.Uninstall build-essential (for packages that build native code during setup).
.rsync-exclude-listlist of the folders that will not be copied to the target and added to the application container.If you store files that are not meant to be shipped to the target in your app folder, add them to the list to save time and storage on deployment.

Deploy and Debug​

After configuring your project, you can now deploy and debug it. Since this is common to all languages supported by the extension, please refer to the section Deploy and Debug from the article Visual Studio Code Extension for Torizon.

Deploy and Release​

After going through the process of deploying and debugging the application, you can now deploy and release it. Since this is common to all languages supported by the extension, please refer to the section Deploy and Release from the article Visual Studio Code Extension for Torizon.