Use the brew python3 instead of Sonoma python3 in VSC

I am using Macos Sonoma
I have installed python with homebrew:

/bin/bash -c “$(curl -fsSL”

This installation results in 3.11

8:23 ~ >which python3
8:24 ~ >python3 --version
Python 3.11.6

After that I have installed the PlatformIO plugin in Visual Code
Everything works fine however I get warnings:

/Users/jaapnoordzij/.platformio/penv/lib/python3.9/site-packages/urllib3/ NotOpenSSLWarning: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the ‘ssl’ module is compiled with ‘LibreSSL 2.8.3’.

It looks like Platform IO is still using the Mac Sonoma version of Python3 :
pio system info reports:

PlatformIO Core 6.1.11
Python 3.9.6-final.0
System Type darwin_x86_64
Platform macOS-14.1.1
File System Encoding utf-8
Locale Encoding UTF-8
PlatformIO Core Directory /Users/jaapnoordzij/.platformio
PlatformIO Core Executable /Users/jaapnoordzij/.platformio/penv/bin/platformio
Python Executable /Users/jaapnoordzij/.platformio/penv/bin/python
Global Libraries 0
Development Platforms 1
Tools & Toolchains 6

How can I change this to use the brew version of python3 ?

I’ve just spent the last three hours of my life trying to get an answer to this question. Is it really that hard? Surely something in penv (pyenv) can make this happen. Any assistance would be great!

So, I’m going to answer my own question – sort of. I followed the advice of another post:

Remove the ~/.platformio/penv & ~/.platformio/python3 folders, and followed by a VSCode restart (twice).

This solved my problem for now. However, python3 is still symlinked to a specific version (.pyenv/versions/3.12.0/bin/python3) rather than the virtual (.pyenv/shims/python) which is preferred – I’m guessing I could change the symlink but I also believe the devs made it this way for some specific reason.

I hope this helps someone else.

If anyone has further insight I’d appreciate it.