Good morning/Afternoon/Evening gentlemen and gentle ladies.
Windows 10, VSCode with PIO on top. I have Python 3.8 installed however I cannot seem to fumble my way through swapping over to have PIO use the local Python rather than the Python env that gets installed. When I searched for “python.exe” on my system I had > 10 interpreters!
I am very sure I am doing it wrong, however, when I did find the choice to change to “system” Python, it seemed to have no effect.
I hate to even ask because this should be so simple. It’s also not earth-shattering, but it’s sort of a pain when the modules I work with are not available in the PIO venv.
Short disclaimer: I’m no expert at this topic at all, but as nobody else is responding, I will try to explain it using my current understanding of this topic.
Python environments are quiet important for different projects which requiere different packages/libraries. Python with pip handles libraries quiet a little different from, for example, C/C++, that’s why project specific environments are often needed. PIO is developed with a certain Python version and certain package versions. As you normally woudn’t want your global python installation to match those exact version necessary, environments are used to easily manage those different instances of Python with versions specific to the project. Trying to force PIO to run on your “global interpreter/isntallation” would probably cause a lot of compatibility issues, so that option is offered nowhere.
If you need the PIO Python environment to use specific packages (for custom scripts I suppose?), you can just install them directly into the Python environment used by PIO. Maybe take a look at this.
Yes, my core issue is having certain packages typically installed via pip available to my PlatformIO environment. I thought to solve it by just making PIO use what I was using for all else but I see where that could get dicey.
I suppose the underlying issue is I don’t seem to be installing packages correctly within PIO’s environment. I had thought I could open my shell from the toolbar and just work from there but it is not working correctly. Is that the proper method, or am I skipping a step? Do I need to invoke a venv first?
At the end of the day, I would like to be able to “work” in the same environment under which PIO does. I’m missing something - any idea what it might be?
Once again disclaimer, I have never worked with the viruatl environment tool PIO uses so maybe you should do your own research; I will just list what I have found doing a quick search.
According to Redirecting... PIO uses the virtualenv tool to create its virtual Python environment (careful when googling as there are multiple tools to achieve this which work differently, I for example know a tool called conda).
You should already have this tool installed as it comes with PIO (I checked on my windows machine using the cmd virtualenv --version). PIOs virtual environment is installed at C:\User\<username>\.platformio\penv by default. There you will have to install the packages you want the PIO Python-environment to be able to use. For me that worked this way:
calling pip list from anywhere, but the penv folder, on my system, I get a list of installed packages in my “global” python installation at C:\python\...
calling pip list while beeing cd-ed to C:\User\<username>\.platformio\penv\Scripts (where the environment has its “private” pip-script) prompts me a smaller list of installed packages in this environment
concluding: to install stuff in the PIO Python-environment your should call pip install while beeing cd-ed to C:\User\<username>\.platformio\penv\Scripts … I guess
PS: I have briefly read about an option to enable seperated environments to be allowed to use globally installed site-packages (which in my mind could cause horrible compatibility issues, but hey :D) … so maybe take a look at this.