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.
F1 on Visual Studio Code and then type
Torizon/Python: Create Python Application to create an application:
After creating it, write the application name on the same command bar:
A bunch of options will appear, make sure to select the right target architecture:
torizon on the username label:
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.
Understand how to add Python packages and more in the next subsections.
Open the Torizon configuration page and edit the
extrapackages configuration, you just need to click on the pen icon:
As an example, add the package python3-pexpect:
This would be the equivalent of running
apt install python3-pexpect on the command-line. It does not use pip.
The Torizon Extension for Visual Studio Code provides the following files for project configuration:
|File||Description||Example Use Case|
|setup.sh||Install additional components.||Run
|requirements.txt||Python packages to be installed via pip, one per line with optional version||Please 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.sh||runs after pip has installed packages in requirements.txt.||Uninstall
|.rsync-exclude-list||list 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.|
First of all, move to the folder created on the previous steps and replace the
main.py content with the following:
#!python import pexpect if __name__ == "__main__": child = pexpect.spawn("echo hello") print(child.readline())
After replacing the content, add a breakpoint on
line 6 by clicking on the left side of the line, it will make a red dot appear.
Note: You may have to enable setting breakpoints anywhere in a file via File → Preferences → Settings →
Debug: Allow Breakpoints Everywhere.
Let the debug process begin! Press F5 and the IDE will build and deploy the debug container image to the computer on module. The application runtime will stop on
This process will take some time for the first time or whenever you edit
.sh files or the
After going on the process of deploying and debugging the application, you can now deploy and release it . Press
F1 in Visual Studio Code to open the command bar and write the command
Torizon/Python: Build release container for Python application.
Note: This entire process can take up to 1 minute.
Your terminal output should be like the following:
Initializing Torizon Python application. Downloading and running docker container used to enable emulation, this may take some time. ARM emulation enabled. Building release container (this may take some time)... Release image has been built successfully.
Attention: Just note that the building process can take some time.
Now that your container was successfully built, you can press
F1 again and enter the
Torizon: Deploy release container, which deploys your container.
Running/restarting release container... Container started. Retrieving container information... Application container is running.
You can confirm if the image was actually deployed to your Torizon device by running the following command on the module:
# docker images
To get more information about Docker Containers and their commands, please refer to Docker Oficial Documentation.