PlatformIO Community

Bundled Python penv usage on MacOS and Windows

Hi,

I have a question on the PIO bundled python venv usage.

My environments are PIO/VSCode on Windows 10 and MacOS respectively.

  • On Windows 10, when I open the terminal panel for a PIO project in the VSCode, I notice the session is in the .platformio/penv venv as below.
    Screen Shot 2021-09-13 at 5.12.12 PM
  • On MacOS, it’s not in the bundled venv, but the MacOS system wide python run time.

And my question is, how can I make the MacOS environment pick the bundled venv as the python run time for the terminal?

Regards,
Yoonseok

Hi,
I’m closing this inquiry by what I think is the answer.

Not sure 100% if it’s the PIO’s design, but Windows installation set the .plaformio/penv/Scritps at the early part of %PATH%, so the bundled python was picked up on invocation, while my MacOS set .platformio/penv/bin at a later part of $PATH so the system wide python was picked up.

So it’s dependent on the %PATH% or $PATH environment variable. And as a convenient guard, I ended up using this steps before running the python code.

#!/bin/sh
which python | grep \.platformio\/penv > /dev/null
if [ $? -ne 0 ] ; then
    source ~/.platformio/penv/bin/activate
fi  
python ~/.platformio/packages/tool-espException/decodeException.py

Regards,
Yoonseok

This might be a bug, please open an issue at https://github.com/platformio/platformio-vscode-ide/issues/

Thank you for your suggestion.

I’m not 100% sure if it is a bug or the like. But it could be justified as an enhancement at least.
Let’s open an issue for an enhancement.

@maxgerhardt

After playing around for some more time, I come to 100% that you’re correct and that it’s a bug. I noticed whenever a PIO terminal gets open, there is some algorithm running already which sets the PATH variable.

And that logic should put the ~/.platformio/python3 ahead of any system wide python directory in the PATH.

Thank you again, and I’ll update the issue.