Upload tool python package requirements

I am working on our Kendryte K210 based board. The official tool provided by Kendryte is the kflash.py tool.

We are using the Raspberry PI as the development platform and also the programmer (using uart and some gpio pins).

We managed to modify the kflash,py to work on PI but we need to toggle a new GPIO to get into download mode.

Now comes the problem.

I am able to override the [env] to point to my custom kflashpy repository. However, my modified python script requires the Raspberry PI library … gpiozero

from gpiozero import LED

When I tried to upload on platform IO it can install this custom package but complains about not able to find LED.

I’m guessing I need to somehow get the package manager to do a pip install. Can anyone point me to the correct way to do this?

PlatformIO executes within its own isolated Python virtual environment as to not touch the system’s libraries in any way.

If you have python libraries to install / needed for an upload, you need to install them in that virtual env, too.

The ways to do that would be to integrate in into a an extra script (docs), you can call into

env.Execute("$PYTHONEXE -m pip install pkg1 pkg2")

and PYTHONEXE will map to the correct executable. That way it’s automated and it can be checked (with a import in a try except statement).

Otherwise, just check for the execute ~/.platformio/penv/Scripts/python and you can execute that python binary with -m pip install .. again. The exact path to the executable is also shown when using pio system info.

@maxgerhardt Thanks alot! Works perfectly.

I am trying to make it seamless for people who create a new project and choose my board (eventually… after I submit a new board).

Is there a way I could automate this process rather than tell people what to do to extra_scripts.py perhaps from the board configuration file?

It would be best if it was directly integrated into the Kendryte platform as an update to the kflash tool, then it can be handled in the official platform code.

Otherwise you either have to go the route of the extra_script per project, or a documented one-time installation command, or fork the entirety of GitHub - sipeed/platform-kendryte210: Kendryte K210: development platform for PlatformIO (which you can link to in the platformio.ini as platfom = <git link of fork>) and add Python code in there (platform.py) to install the package.

Got it. Thanks alot.