# Problems when running pystan on windows 10

**URL:** <https://discourse.mc-stan.org/t/problems-when-running-pystan-on-windows-10/28544>\
**Category:** PyStan\
**Tags:** pystan, fitting-issues, bug\
**Created:** [August 16, 2022, 7:22am UTC](https://discourse.mc-stan.org/t/problems-when-running-pystan-on-windows-10/28544 "2022-08-16T07:22:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardhansson](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@richardhansson](https://discourse.mc-stan.org/u/richardhansson)\
**Post date:** [August 16, 2022, 7:22am UTC](https://discourse.mc-stan.org/t/problems-when-running-pystan-on-windows-10/28544/1 "2022-08-16T07:22:54Z")

</div>

I been trying to get pystan working for quite a while on windows 10.  
An package called orbit relies heavily on it and i am trying to use it without luck where the errors always appears upstream in stan.

Operating system: windows 10  
Python version: 3.7.12  
Pystan version: 2.19.1.1  
compiler: mingw32

Code to reproduce(notice the environment variable INCLUDE, this was necessary to try to hack through the io.h file not found bug and basestd.h not found and vcruntime.h not found etc):

```nohighlight
import pandas as pd
  import numpy as np

  pd.set_option('display.float_format', lambda x: '%.5f' % x)
  import matplotlib
  import matplotlib.pyplot as plt

  import orbit
  from orbit.models import KTRLite, KTR

  from orbit.utils.features import make_fourier_series_df, make_fourier_series
  from orbit.diagnostics.plot import plot_predicted_data, plot_predicted_components
  from orbit.diagnostics.metrics import smape
  from orbit.utils.dataset import load_iclaims, load_electricity_demand

  df = load_iclaims()

  DATE_COL = 'week'
  RESPONSE_COL = 'claims'

  print(df.shape)

  df.head()

  print(f'starts with {df[DATE_COL].min()}\nends with {df[DATE_COL].max()}\nshape: {df.shape}')

  test_size = 52

  train_df = df[:-test_size]
  test_df = df[-test_size:]

  ktr = KTR(
      date_col=DATE_COL,
      response_col=RESPONSE_COL,
      # regressor_col=['trend.unemploy', 'trend.filling', 'trend.job'],
      regressor_col=['trend.unemploy'],
      seasonality=[52],
      seasonality_fs_order=[3],
      level_knot_scale=.1,
      level_segments=10,
      regression_segments=0,
      regression_rho=0.15,
      # pyro optimization parameters
      seed=8888,
      num_steps=1000,
      num_sample=1000,
      learning_rate=0.1,
      estimator='pyro-svi',
      n_bootstrap_draws=-1,
      ktrlite_optim_args=dict()
  )

  import os

  os.environ['CC'] = 'gcc-10'
  os.environ['CXX'] = 'g++-10'
  os.environ['INCLUDE'] = 'C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt;' \
                          'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\MSVC\\14.33.31629\\include;' \
                          'C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared'

  ktr.fit(train_df)

```

trace back(i cant post hte whole one due to charlimit):

WARNING:pystan:MSVC compiler is not supported  
stanfit4anon\_model\_ce583eb84b35032d795f7056cd3c761e\_9175705935281291528.cpp  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\numpy\core\include\numpy\npy\_1\_7\_deprecated\_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY\_NO\_DEPRECATED\_API NPY\_1\_7\_API\_VERSION  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/meta/seq\_view.hpp(145): warning C4267: ‘return’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/multiply\_lower\_tri\_self\_transpose.hpp(19): warning C4244: ‘initializing’: conversion from ‘Eigen::EigenBase::Index’ to ‘int’, possible loss of data  
with  
[  
Derived=Eigen::Matrix\<double,-1,-1,0,-1,-1\>  
]  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/multiply\_lower\_tri\_self\_transpose.hpp(27): warning C4244: ‘initializing’: conversion from ‘Eigen::EigenBase::Index’ to ‘int’, possible loss of data  
with  
[  
Derived=Eigen::Matrix\<double,-1,-1,0,-1,-1\>  
]  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/csr\_u\_to\_z.hpp(28): warning C4267: ‘argument’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/matrix\_exp\_action\_handler.hpp(118): warning C4244: ‘initializing’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/to\_matrix.hpp(136): warning C4267: ‘initializing’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/to\_row\_vector.hpp(31): warning C4267: ‘initializing’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/to\_vector.hpp(31): warning C4267: ‘initializing’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/welford\_covar\_estimator.hpp(31): warning C4244: ‘return’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/welford\_var\_estimator.hpp(31): warning C4244: ‘return’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\src\stan/io/dump.hpp(243): warning C4101: ‘exc’: unreferenced local variable  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\src\stan/io/dump.hpp(270): warning C4101: ‘exc’: unreferenced local variable  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\src\stan/io/dump.hpp(284): warning C4101: ‘exc’: unreferenced local variable  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/mat/meta/operands\_and\_partials.hpp(42): warning C4267: ‘return’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/mat/meta/operands\_and\_partials.hpp(155): warning C4267: ‘return’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/bessel\_first\_kind.hpp(19): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/bessel\_first\_kind.hpp(20): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/bessel\_second\_kind.hpp(19): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/bessel\_second\_kind.hpp(20): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/modified\_bessel\_first\_kind.hpp(19): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/modified\_bessel\_first\_kind.hpp(20): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/modified\_bessel\_second\_kind.hpp(19): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/modified\_bessel\_second\_kind.hpp(20): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/scal/fun/rising\_factorial.hpp(18): warning C4244: ‘argument’: conversion from ‘double’ to ‘int’, possible loss of data  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/rev/mat/fun/cholesky\_decompose.hpp(82): warning C4244: ‘initializing’: conversion from ‘Eigen::EigenBase::Index’ to ‘int’, possible loss of data  
with  
[  
Derived=Eigen::Matrixstan::math::var,-1,-1,0,-1,-1  
]

C:\Users\User1\AppData\Local\Temp\pystan\_xzmnrs8w\anon\_model\_ce583eb84b35032d795f7056cd3c761e.hpp(280): note: ‘void stan::math::assign(T\_lhs &,const T\_rhs &)’: expects 2 arguments - 1 provided  
C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\stan\lib\stan\_math\stan/math/prim/mat/fun/assign.hpp(47): note: see declaration of ‘stan::math::assign’  
C:\Users\MAXIMI~1\AppData\Local\Temp\pystan\_xzmnrs8w\stanfit4anon\_model\_ce583eb84b35032d795f7056cd3c761e\_9175705935281291528.cpp(5224): warning C4267: ‘=’: conversion from ‘size\_t’ to ‘int’, possible loss of data  
Traceback (most recent call last):  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\_msvccompiler.py”, line 396, in compile  
self.spawn(args)  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\_msvccompiler.py”, line 502, in spawn  
return super().spawn(cmd)  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\ccompiler.py”, line 910, in spawn  
spawn(cmd, dry\_run=self.dry\_run)  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\spawn.py”, line 38, in spawn  
\_spawn\_nt(cmd, search\_path, dry\_run=dry\_run)  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\spawn.py”, line 81, in \_spawn\_nt  
“command %r failed with exit status %d” % (cmd, rc))  
distutils.errors.DistutilsExecError: command ‘C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\x64\cl.exe’ failed with exit status 2  
During handling of the above exception, another exception occurred:  
Traceback (most recent call last):  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\site-packages\pystan\model.py”, line 378, in **init**  
build\_extension.run()  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\command\build\_ext.py”, line 340, in run  
self.build\_extensions()  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\command\build\_ext.py”, line 449, in build\_extensions  
self.\_build\_extensions\_serial()  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\command\build\_ext.py”, line 474, in \_build\_extensions\_serial  
self.build\_extension(ext)  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\command\build\_ext.py”, line 534, in build\_extension  
depends=ext.depends)  
File “C:\Users\User1\anaconda3\envs\stan\_env2\lib\distutils\_msvccompiler.py”, line 398, in compile  
raise CompileError(msg)  
distutils.errors.CompileError: command ‘C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\x64\cl.exe’ failed with exit status 2  
python-BaseException

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [August 16, 2022, 7:42am UTC](https://discourse.mc-stan.org/t/problems-when-running-pystan-on-windows-10/28544/2 "2022-08-16T07:42:07Z")

</div>

It looks like you’re using the MSVC compiler, which isn’t supported:

```nohighlight
WARNING:pystan:MSVC compiler is not supported

```

@ariddell it looks like the Pystan2 on Windows doc link is broken: [https://pystan2.readthedocs.io/en/latest/\_windows](https://pystan2.readthedocs.io/en/latest/_windows)

What’s the recommended setup for Pystan2 on windows these days?

---

<div class="post-metadata">

**Author:** ![richardhansson](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@richardhansson](https://discourse.mc-stan.org/u/richardhansson)\
**Post date:** [August 16, 2022, 8:03am UTC](https://discourse.mc-stan.org/t/problems-when-running-pystan-on-windows-10/28544/3 "2022-08-16T08:03:30Z")

</div>

forgot to mention that i installed the c+±compiler following [PyStan on Windows — PyStan 2.19.1.1 documentation](https://pystan2.readthedocs.io/en/latest/windows.html)  
and checked that the distutils.cfg file declares compiler=mingw32  
but the warning however seems problematic.  
note the environment variable ‘C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include;’  
which is needed? since i otherwise run into a cant find vcruntime.h error.

when tracking down on the warning i found that build\_extension.compiler is None here and not explicitly msvc:  
module model, row 325  
if build\_extension.compiler in (None, ‘msvc’):  
logger.warning(“MSVC compiler is not supported”)

---

<div class="post-metadata">

**Author:** ![ahartikainen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ahartikainen/32/321_2.png) [@ahartikainen](https://discourse.mc-stan.org/u/ahartikainen)\
**Post date:** [August 16, 2022, 8:33am UTC](https://discourse.mc-stan.org/t/problems-when-running-pystan-on-windows-10/28544/4 "2022-08-16T08:33:25Z")

</div>

Your mingw-w64 compiler is not installed correctly so Python can not find it.

Create a new conda environment and install mingw-w64 + libpython and try again.

PyStan2 is not supported officially but we can always do some debugging here.

Also, don’t try to push msvc files for the process.

---

<div class="post-metadata">

**Author:** ![richardhansson](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@richardhansson](https://discourse.mc-stan.org/u/richardhansson)\
**Post date:** [August 16, 2022, 8:41am UTC](https://discourse.mc-stan.org/t/problems-when-running-pystan-on-windows-10/28544/5 "2022-08-16T08:41:04Z")

</div>

now i see what happened: in my distutils.cfg file i solely had [build\_ext] and not [build] … this solved the error.
