I have a Python project which (amongst other things) manages PlatformIO projects.
Since PlaformIO doesn’t expose any API, I’m using the subprocess module like this (after installing the platformio package via pip):
subprocess.run(
['pio', 'project', 'init',
'-d', path,
'-b', board_name,
'-O', 'framework=arduino'],
)
So far so good, now however I wanted to bundle my Python project into a single executable using PyInstaller, and now I’m getting this error:
File "/home/USERNAME/.local/bin/pio", line 5, in <module>
from platformio.__main__ import main
ModuleNotFoundError: No module named 'platformio'
PyInstaller explicitly states that using subprocesses may lead to this kind of behavior due to the process environment or path variables, but I’m apparently unable to properly set this up in a way that works. I tried modifying a copy of os.environ['PATH']
and passing it to the subprocess, but that did nothing.
Using which pio
in a subprocess whinin my Python project correctly returns PATH_TO_MY_VENV/bin/pio
, while it returns /home/USERNAME/.local/bin/pio
in the packaged app, which is an indicator that it’s not using the correct PlatformIO entrypoint.
It’s certainly not that the platformio package isn’t bundled with the rest of the app, because using import platformio
with print(platformio.VERSION)
correctly returns (6, 1, 13)
on both versions of the program.
(Side note: I have a PlatformIO installation within my Python virtual environment from installing it via pip as well as a system-wide installation for other non-Python-related projects)
AirWick is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.