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\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\program files\python39\lib\site-packages\platformio\project\commands\init.py", line 94, in project_init_cmd
    install_project_dependencies(
  File "c:\program files\python39\lib\site-packages\platformio\package\commands\install.py", 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\install.py", 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\install.py", line 247, in _install_project_env_libraries
    env_lm.install(
  File "c:\program files\python39\lib\site-packages\platformio\package\manager\_install.py", 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\_install.py", line 113, in _install
    self.call_pkg_script(pkg, "postinstall")
  File "c:\program files\python39\lib\site-packages\platformio\package\manager\base.py", line 335, in call_pkg_script
    subprocess.run(
  File "c:\program files\python39\lib\subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'c:\program files\python39\python.exe port/platform/platformio/pio_post_install.py' 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/after_install.py"]
}

Passing script as an argument.

1 Like

Magic! Thank you, that worked :-).