Installing python packages

Colibri iMX6 512MB IT

Hi,

Trying to run some python code
it seems I can import os, time, json and datetime,
but I cannot seem to

 import paho.mqtt.client as mqtt

from the eclipse site:

it says I should type :

pip install paho-mqtt

which I can do from my container if I do a
docker run -it … bash

torizon@89d300cf06ac:/$ pip install paho-mqtt
Defaulting to user installation because normal site-packages is not writeable
Collecting paho-mqtt
  Downloading paho-mqtt-1.6.1.tar.gz (99 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 99.4/99.4 kB 1.7 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: paho-mqtt
  Building wheel for paho-mqtt (setup.py) ... done
  Created wheel for paho-mqtt: filename=paho_mqtt-1.6.1-py3-none-any.whl size=62114 sha256=3109faa6d44fd1888b0c971d10f6f7abd356a426b0eab1a1c6a3369057d22bed
  Stored in directory: /home/torizon/.cache/pip/wheels/0f/90/29/db29bb8ddc98ec5f2363b959130c9ddbcf5cfdb4a00b6184dd
Successfully built paho-mqtt
Installing collected packages: paho-mqtt
Successfully installed paho-mqtt-1.6.1

then I can type

$ python3 main.py

and the program works.

Question: How do I do this from VSCODE, i.e. without having to go into the container and do the pip install myself?

I tried putting it under Configuration/Commands: pip install paho-mqtt but im not sure if its working there… Here is an excerpt from my config.yaml

props:
    common:
        appargs: ''
        appname: DeviceHandler
        arg: ''
        buildcommands: RUN usermod -a -G gpio,dialout torizon
        buildfiles: ''
        command: pip install paho-mqtt
        devpackages: paho
        env: ''
        expose: ''
        extrapackages: iproute2 can-utils python3-can python3-pexpect libgpiod2 tzdata
        language: python
        main: main.py
        preinstallcommands: ''
        runtime: python3
        sdkpostinstallcommands: ''
        sdkpreinstallcommands: ''
        targetcommands: ''
        targetfiles: ''
    debug:
        arg: 'ARG SSHUSERNAME=#%application.username%#

Greetings @leighjboyd,

Please see the various configuration options provided by our extension here: Python Development and Debugging on TorizonCore Using Visual Studio Code | Toradex Developer Center

As seen there is a file called requirments.txt any package listed in this file will be installed with pip upon building the container. This file is a common configuration file used in Python if you want to look up how the syntax for the file works.

Best Regards,
Jeremias