Pystan msvc linker error

When testing pystan- via Anaconda on Windows 10, pystan defaults to MSVC compiler and not gcc mingw-5.3.0 (installed from -c msys). This is part of the testing I’m doing for pybrms @ahartikainen

import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)

Please provide this additional information in addition to your question:

  • Operating System: Window 10
  • Python Version: 3.7.0
  • PyStan Version:
  • Compiler/Toolkit: gcc-5.3.0 but this is not accessed

I manually created disutils.cfg to reference mingw32 as the compiler as per the instructions Configuring C++ compiler for Pystan on Windows



I would start by first creating a new conda environment

conda create -n stan -c  conda-forge
conda activate stan

And then install libpython and gcc compiler

Make sure that gcc compiler is shown in cmd.

Install pystan.

Run your code with python, if running with jupyter you should start the jupyter from cmd with activated conda environment.

@ahartikainen Thanks for the feedback and directions. I will test and let you know how it goes. So that I understood you correctly - “Make sure that gcc compiler is shown in cmd” - I usually test the compiler by running g++ -v. Is this what you are referring to?


One problem might be running specific python from “wrong” environment (e.g. jupyter/spyder(?)/pycharm have options to change python env but this does not change the PATH info → gcc is not found

@ahartikainen thanks for the confirmation. I had made that mistake a few times, but now launch jupyter from the environment command prompt. Prior to testing in jupyter, I always test the basic pystan at the command prompt itself.
I will be testing this today and update here. Thanks again for your time. I’m hoping to create documentation for different tools within the stan family for installation and usage for first time users in the Windows space.

1 Like

@ahartikainen the steps you laid out worked perfectly to get Pystan= working nicely on Windows using gcc-5.3.0. Thank you! I could run the 8schools example using a Jupyter notebook
I will now check to see if I can build this further for pybrms with rpy2 and brms

1 Like

@ahartikainen Further success with installing r-base-4.1.2 rpy2-3.4.5 and pybrms-0.0.33 and running the model using the epilepsy data from within brms R package

I will post these instructions at github/pybrms.

1 Like

@ahartikainen Here is the link to complete Pystan and Pybrms setup I posted at GitHub:

Pystan and Pybrms setup resolution

1 Like