el_pako (el_pako) wrote,
el_pako
el_pako

Installing Pystan on macOS Mojave - fix for gcc error

Installing Pystan on macOS Mojave 10.14.

Most useful post:
https://github.com/stan-dev/pystan/issues/643

Myths:
- you need to install Xcode. Not really, because you can go with xcode-select:
xcode-select --install
- you need gcc installed. Actually you will be better with newest clang

Installing pyStan:
conda create -n stan python=3.7 numpy cython pystan -c conda-forge
conda activate stan

## installing gcc
conda install clang_osx-64 clangxx_osx-64 -c conda-forge

export CC=x86_64-apple-darwin13.4.0-clang
export CXX=x86_64-apple-darwin13.4.0-clang++

Testing:
Create new file and save it as 'sample.py':
import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code, verbose=True) # this will take a minute
fit = model.sampling(n_jobs=1)
y = fit.extract()['y']
print(fit)
print(y.mean()) # should be close to 0


Run this file:
python sample.py
Tags: #macos, #pystan, #python
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 0 comments