How to use own python libraries in extra_script.py

Update:

This works fine running with pio test which uses my own external installation of PIO with my own python packages. But I can’t get this work with the integrated test buttons in the pio venv without running source ~/.platformio/penv/bin/activate and pip install ....

How would I install a python package ‘logic2-automation’ in the pio virtual environment for testing? I understand how to do it for builds with this link, but this doesn’t seem to work with the testing environment


I’m not sure if I need the env variable. I was deriving this from the scripting tutorial. I only need a python package for the runner file. I don’t need to edit any C++ environment variables at the moment.

If I was to add

def configure_build_env(self, env):
        env.Execute("$PYTHONEXE -m pip list")

        # Install custom packages from the PyPi registry
        env.Execute("$PYTHONEXE -m pip install saleae") 
        return env

Into class CustomTestRunner(UnityTestRunner): as a method, the original import at the top of the file import saleae would fail.

I ran a regular build with extra_scripts = extra_script.py which installed the package I need in the PIO environment, but this didn’t seem to transfer to the testing enviroment.