distutils.errors.DistutilsExecError occured when run python script using pystan?

I have installed pystan on window 10. and successfully runimport pystan in shell as well as gcc -v. When i tried to use pystan to predict some current data. it reported “distutils.errors.DistutilsExecError”. I tried a lot of ways to solve it. but all seems in vain. The python version is 3.9.. By the way, someone told me it works in python3.6.

Here is the detail:

Traceback (most recent call last):
  File "D:\program\python\lib\site-packages\setuptools\_distutils\cygwinccompiler.py", line 143, in _compile
    self.spawn(
  File "D:\program\python\lib\site-packages\setuptools\_distutils\ccompiler.py", line 1041, in spawn
    spawn(cmd, dry_run=self.dry_run, **kwargs)
  File "D:\program\python\lib\site-packages\setuptools\_distutils\spawn.py", line 70, in spawn
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command 'D:\\program\\x86_64-15.2.0-release-win32-seh-ucrt-rt_v13-rev0\\mingw64\\bin\\gcc.exe' failed with exit code 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\sky\Desktop\新建文本文档 (2).py", line 58, in <module>
    model = pystan.StanModel(model_code=bsts_code)
  File "D:\program\python\lib\site-packages\pystan\model.py", line 378, in __init__
    build_extension.run()
  File "D:\program\python\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 345, in run
    self.build_extensions()
  File "D:\program\python\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 467, in build_extensions
    self._build_extensions_serial()
  File "D:\program\python\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 493, in _build_extensions_serial
    self.build_extension(ext)
  File "D:\program\python\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 548, in build_extension
    objects = self.compiler.compile(
  File "D:\program\python\lib\site-packages\setuptools\_distutils\ccompiler.py", line 600, in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  File "D:\program\python\lib\site-packages\setuptools\_distutils\cygwinccompiler.py", line 147, in _compile
    raise CompileError(msg)
distutils.errors.CompileError: command 'D:\\program\\x86_64-15.2.0-release-win32-seh-ucrt-rt_v13-rev0\\mingw64\\bin\\gcc.exe' failed with exit code 1


It looks like you are on Windows, this means you are limited to PyStan 2 which is indeed not functional in more recent versions of Python. It’s highly recommended you switch to using the cmdstanpy package instead

it boils down to that windows is not compatible with PyStan 2, I tried cmdstanpy. Thank you so much