Library.json with postinstall script fails if Python path has a space in it

Hi there. I have a library.json which includes a "scripts": "postinstall" pointing to a Python script.

My copy of Python is installed in C:\Program Files\Python39; when PlatformIO is installed it creates a virtual environment and appears to run correctly (see bottom of this post). However, when Platform IO calls the posinstall script from library.json it uses the full Python path, unquoted, which of course fails:

'c:\program' is not recognized as an internal or external command,
operable program or batch file.
  File "c:\program files\python39\lib\site-packages\click\", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\program files\python39\lib\site-packages\platformio\project\commands\", line 94, in project_init_cmd
  File "c:\program files\python39\lib\site-packages\platformio\package\commands\", line 106, in install_project_dependencies
    already_up_to_date = not install_project_env_dependencies(env, options)
  File "c:\program files\python39\lib\site-packages\platformio\package\commands\", line 132, in install_project_env_dependencies
    _install_project_env_libraries(project_env, options),
  File "c:\program files\python39\lib\site-packages\platformio\package\commands\", line 247, in _install_project_env_libraries
  File "c:\program files\python39\lib\site-packages\platformio\package\manager\", line 48, in install
    pkg = self._install(spec, skip_dependencies=skip_dependencies, force=force)
  File "c:\program files\python39\lib\site-packages\platformio\package\manager\", line 113, in _install
    self.call_pkg_script(pkg, "postinstall")
  File "c:\program files\python39\lib\site-packages\platformio\package\manager\", line 335, in call_pkg_script
  File "c:\program files\python39\lib\", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'c:\program files\python39\python.exe port/platform/platformio/' returned non-zero exit status 1.

Am I doing something wrong here, or are spaces not supported in the path to Python?

Installer version: 1.1.2
Platform: Windows-10
Python version: 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
Python path: C:\Program Files\Python39\python.exe
Creating a virtual environment at C:\Users\rmea\.platformio\penv
Updating Python package manager (PIP) in a virtual environment
PIP has been successfully updated!
Virtual environment has been successfully created!

This should work

"scripts": {
    "postinstall": ["scripts/"]

Passing script as an argument.

1 Like

Magic! Thank you, that worked :-).