# Does pystan v.2.19.1.1 work on pure Windows 10 (not WSL)?

**URL:** <https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960>\
**Category:** General\
**Tags:** pystan\
**Created:** [September 28, 2022, 7:59am UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960 "2022-09-28T07:59:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![don\_quixote](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@don\_quixote](https://discourse.mc-stan.org/u/don_quixote)\
**Post date:** [September 28, 2022, 7:59am UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960/1 "2022-09-28T07:59:20Z")

</div>

I followed guidelines here: [PyStan on Windows — PyStan 2.19.1.1 documentation](https://pystan2.readthedocs.io/en/latest/windows.html)

I used new conda environment. But basic test on the same page does not work!

It gives me an error:

```nohighlight
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_5944b02c79788fa0db5b3a93728ca2bf NOW.
Traceback (most recent call last):
  File "C:\Users\xyz\Anaconda3\lib\site-packages\setuptools\_distutils\unixccompiler.py", line 267, in link
    self.spawn(linker + ld_args)
  File "C:\Users\xyz\Anaconda3\lib\site-packages\setuptools\_distutils\ccompiler.py", line 987, in spawn
    spawn(cmd, dry_run=self.dry_run, **kwargs)
  File "C:\Users\xyz\Anaconda3\lib\site-packages\setuptools\_distutils\spawn.py", line 70, in spawn
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command 'C:\\Users\\xyz\\Anaconda3\\Library\\mingw-w64\\bin\\g++.exe' failed with exit code 1

```

so my question is: does pystan v.2.19.1.1 work on pure Windows 10 (not WSL)?

---

<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:** [September 28, 2022, 9:24am UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960/2 "2022-09-28T09:24:09Z")

</div>

Maybe, probably need to build it manually (not sure of python versions)

Why do you need pystan?

Could you use CmdStanPy?

---

<div class="post-metadata">

**Author:** ![don\_quixote](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@don\_quixote](https://discourse.mc-stan.org/u/don_quixote)\
**Post date:** [September 28, 2022, 6:38pm UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960/4 "2022-09-28T18:38:00Z")

</div>

pystan 2 is a part of old legacy stack. but now I try to run it on windows, instead of linux. it is a pain!

Do I need to setup gcc for newer version? the one you recommend by the link above, ~5.3 from 2015.

What are best practices in setting up gcc? Can I use external compiler and hook it up somehow? I see people pass CC and CXX env variables …

---

<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:** [September 29, 2022, 3:29am UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960/5 "2022-09-29T03:29:19Z")

</div>

Yes, it is a pain.

I’m not sure if there are any new gcc compilers for python that work. I think I asked about this a few years ago from the devs who created the mingw-w64 version and they were not interested having a new version. At the same time python (the main library) devs decided to go with msvc support only on windows and given that there is/was unresolved bug with templates that Stan libs hit we were starting to run out of options.

I can try tomorrow couple of options and let see if they work.

It has been sometime since I last tried to use mingw-w64 so maybe current python versions has something that breaks it.

But are the old libs using the lp calculation or do they only use sampling etc? Maybe you could hack the “system” by wrapping CmdStanPy functionality and save it in a file called pystan and then import it as “pystan” (or make it a package and install).

---

<div class="post-metadata">

**Author:** ![don\_quixote](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@don\_quixote](https://discourse.mc-stan.org/u/don_quixote)\
**Post date:** [September 29, 2022, 3:47am UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960/6 "2022-09-29T03:47:26Z")

</div>

in legacy stack it is a point estimate even, I think it was dropped in stan version 3.

this method:

> ```
> def optimizing(self, data=None, seed=None,
> init='random', sample_file=None, algorithm=None,
> verbose=False, as_vector=True, **kwargs):
> """Obtain a point estimate by maximizing the joint posterior.
> 
> ```

---

<div class="post-metadata">

**Author:** ![don\_quixote](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@don\_quixote](https://discourse.mc-stan.org/u/don_quixote)\
**Post date:** [September 30, 2022, 6:52am UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960/7 "2022-09-30T06:52:17Z")

</div>

FYI: I managed to run it all using WSL.

---

<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:** [September 30, 2022, 7:50am UTC](https://discourse.mc-stan.org/t/does-pystan-v-2-19-1-1-work-on-pure-windows-10-not-wsl/28960/8 "2022-09-30T07:50:13Z")

</div>

Edit. Probably not fixable:

Compilation throws:  
`division by zero is not a constant-expression` ok, probably something has changed in cython etc and things will fail. Probably using older cython versions with older python (3.7 etc) is the only solution.

> <https://github.com/cython/cython/issues/3405>
>
> I can compile Cython generated code on the 32-bit version of Mingw, but on the 6…4-bit version, I get these errors:
> C:\\py\>gcc -m64 pathfinder.cpp
> pathfinder.cpp:215:41: warning: division by zero \[-Wdiv-by-zero\]
> enum { \_\_pyx\_check\_sizeof\_voidp = 1 / (int)(SIZEOF\_VOID\_P == sizeof(void\*))
> };
> ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> pathfinder.cpp:215:79: error: division by zero is not a constant expression
> enum { \_\_pyx\_check\_sizeof\_voidp = 1 / (int)(SIZEOF\_VOID\_P == sizeof(void\*))
> };
> ^
> 
> pathfinder.cpp:215:41: error: '(1 / 0)' is not a constant expression
> enum { \_\_pyx\_check\_sizeof\_voidp = 1 / (int)(SIZEOF\_VOID\_P == sizeof(void\*))
> };
> ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> pathfinder.cpp:215:79: error: enumerator value for '\_\_pyx\_check\_sizeof\_voidp' is
> not an integer constant
> enum { \_\_pyx\_check\_sizeof\_voidp = 1 / (int)(SIZEOF\_VOID\_P == sizeof(void\*))
> };
> ^

### old msg

Ok, I did some testing

I had an environment with `mingw-w64` toolchain and `libpython` installed as in the instructions (I had this installed for another things).

Then to really use the mingw, you need to edit the following files

```
PYTHONPATH\\Lib\\distutils\distutils.cfg
PYTHONPATH\\Lib\\site-packages\setuptools\_distutils\distutils.cfg

```

and add both of them the following lines

```
[build]
compiler=mingw32

```

They had `[build-ext]` already defined, but not sure what is it used for.

Then before trying to install `pystan` I needed to install `numpy` and `cython`.

First try failed to install `pystan` due to path problems. So I needed to go and enable long paths for Windows 11 (I used GPEDIT solution here [https://thegeekpage.com/make-windows-11-accept-file-paths-over-260-characters/](https://thegeekpage.com/make-windows-11-accept-file-paths-over-260-characters/)) and restarted the machine.

~~After this I was able to install pystan and the example model compiled and sampled nicely.~~

nope, I was too quick to write this, some error popped up, not sure what, will do some more debugging.

So what has changed is that Cython apparently wants to use setuptools/\_distutils instead of the main distutils and things fails due to this.

There was small set of code that revealed this

```
from Cython.Build.Inline import Distribution
dist.find_config_files()
# ['C:\\Users\\username\\miniconda3\\envs\\stan\\lib\\site-packages\\setuptools\\_distutils\\distutils.cfg']

```
