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

I followed guidelines here: PyStan on Windows — PyStan documentation

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

It gives me an error:

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\", line 267, in link
    self.spawn(linker + ld_args)
  File "C:\Users\xyz\Anaconda3\lib\site-packages\setuptools\_distutils\", line 987, in spawn
    spawn(cmd, dry_run=self.dry_run, **kwargs)
  File "C:\Users\xyz\Anaconda3\lib\site-packages\setuptools\_distutils\", 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. work on pure Windows 10 (not WSL)?

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

Why do you need pystan?

Could you use CmdStanPy?

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 …

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).

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.

FYI: I managed to run it all using WSL.

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.

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


and add both of them the following lines


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 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
# ['C:\\Users\\username\\miniconda3\\envs\\stan\\lib\\site-packages\\setuptools\\_distutils\\distutils.cfg']
1 Like