If you want to run PyStan on Windows, it's easiest to use Anaconda, and the official documentation also describes how to install using Anaconda. PyStan on Windows — PyStan documentation
If you don't use Anaconda, your next option would be to consider running PyStan on a Linux virtual environment, such as with WSL 2.
But that's not even possible, ** what if you want to run PyStan on Windows that doesn't have access to Anaconda or Linux virtual environments **?
I tried it on Windows Server 2019 built on Amazon EC2, but it should be about the same on Windows 10. (suitable)
It doesn't seem to matter much, but I use PowerShell to execute commands.
First, install Python.
This time I installed Python 3.8.6. I will omit it because I just download the installer normally and click it.
Python Release Python 3.8.6 | Python.org
PyStan uses the C ++ compiler at runtime and must be installed.
According to the official document, "MSVC compiler is not supported.", But when I tried it with MinGW-w64, it didn't work ... [^ mingw-w64] And it worked fine for Microsoft Visual C ++, which seems to be unsupported, so this time I will write about this method.
[^ mingw-w64]: I installed MinGW-w64 and set the build-time compiler = mingw32 option in distutils.cfg through the path, but what else did I need?
Download and run the "Build Tools for Visual Studio 2019" installer from the download page. (In the lower menu) Download Visual Studio 2019 for Windows & Mac
When the installer starts, check "C ++ Build Tool" and install it.
Install Cython and NumPy in advance, as you will need them when installing PyStan.
$ pip install cython numpy
The latest version as of November 2020 is 2.19, but it didn't work, so I'll include 2.17. [^ pystan2.19]
[^ pystan2.19]: If pystan == 2.19, the installation will end immediately, but when importing, an error such as "Import Error: DLL load failed while importing _api" will appear and it cannot be used. It looks like the build isn't running during installation, but I don't know the details.
$ pip install pystan==2.17.1.0
Let's run a simple sample code.
from pystan import StanModel
model = StanModel(model_code="parameters {real y;} model {y ~ normal(0,1);}")
print(model.sampling().extract()["y"].mean())
Success if a 0-like value is displayed without any error.
Windows I don't know anything.
And who is in demand for this article? ?? ??
Recommended Posts