Hi Pystan Experts,
Sorry for reaching out but I am running in circle just to find a way to install and run pystan properly. I have followed all the links: PyStan on Windows — PyStan 2.19.1.1 documentation
I successfully installed pystan in both anaconda and pip and what makes me so frustrated is I couldn’t run it. I am not sure what else to do. This is the error message, I install visual studio 19 and I am not sure what else to do. If anyone have any experience with this, I would truly appreciate any feedback and guidance.
AppData\Local\Temp\pystan_5e4xznjx\stanfit4anon_model_548939bc33801f8115bc26206558c913_1778331446179605254.pyx
building 'stanfit4anon_model_548939bc33801f8115bc26206558c913_1778331446179605254' extension
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\msvc.py:275, in _msvc14_get_vc_env(plat_spec)
274 try:
--> 275 out = subprocess.check_output(
276 'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
277 stderr=subprocess.STDOUT,
278 ).decode('utf-16le', errors='replace')
279 except subprocess.CalledProcessError as exc:
File ~\anaconda3\envs\stan_env\lib\subprocess.py:415, in check_output(timeout, *popenargs, **kwargs)
413 kwargs['input'] = empty
--> 415 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
416 **kwargs).stdout
File ~\anaconda3\envs\stan_env\lib\subprocess.py:516, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
515 if check and retcode:
--> 516 raise CalledProcessError(retcode, process.args,
517 output=stdout, stderr=stderr)
518 return CompletedProcess(process.args, retcode, stdout, stderr)
CalledProcessError: Command 'cmd /u /c "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 && set' returned non-zero exit status 255.
The above exception was the direct cause of the following exception:
DistutilsPlatformError Traceback (most recent call last)
Input In [4], in <cell line: 51>()
13 ctrl_data = {
14 'N': len(df_ctrl),
15 'K1': len(pos_vars),
(...)
20 'max_intercept': min(df_ctrl['sales'])
21 }
23 ctrl_code1 = '''
24 data {
25 int N; // number of observations
(...)
48 }
49 '''
---> 51 sm1 = pystan.StanModel(model_code=ctrl_code1, verbose=True)
52 fit1 = sm1.sampling(data=ctrl_data, iter=2000, chains=4)
53 fit1_result = fit1.extract()
File ~\anaconda3\envs\stan_env\lib\site-packages\pystan\model.py:378, in StanModel.__init__(self, file, charset, model_name, model_code, stanc_ret, include_paths, boost_lib, eigen_lib, verbose, obfuscate_model_name, extra_compile_args, allow_undefined, include_dirs, includes)
375 orig_stderr = pystan.misc._redirect_stderr()
377 try:
--> 378 build_extension.run()
379 finally:
380 if redirect_stderr:
381 # restore stderr
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\_distutils\command\build_ext.py:346, in build_ext.run(self)
343 self.compiler.set_link_objects(self.link_objects)
345 # Now actually compile and link everything.
--> 346 self.build_extensions()
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\_distutils\command\build_ext.py:466, in build_ext.build_extensions(self)
464 self._build_extensions_parallel()
465 else:
--> 466 self._build_extensions_serial()
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\_distutils\command\build_ext.py:492, in build_ext._build_extensions_serial(self)
490 for ext in self.extensions:
491 with self._filter_build_errors(ext):
--> 492 self.build_extension(ext)
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\_distutils\command\build_ext.py:547, in build_ext.build_extension(self, ext)
544 for undef in ext.undef_macros:
545 macros.append((undef,))
--> 547 objects = self.compiler.compile(
548 sources,
549 output_dir=self.build_temp,
550 macros=macros,
551 include_dirs=ext.include_dirs,
552 debug=self.debug,
553 extra_postargs=extra_args,
554 depends=ext.depends,
555 )
557 # XXX outdated variable, kept here in case third-part code
558 # needs it.
559 self._built_objects = objects[:]
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\_distutils\_msvccompiler.py:361, in MSVCCompiler.compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
348 def compile( # noqa: C901
349 self,
350 sources,
(...)
357 depends=None,
358 ):
360 if not self.initialized:
--> 361 self.initialize()
362 compile_info = self._setup_compile(
363 output_dir, macros, include_dirs, sources, depends, extra_postargs
364 )
365 macros, objects, extra_postargs, pp_opts, build = compile_info
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\_distutils\_msvccompiler.py:241, in MSVCCompiler.initialize(self, plat_name)
238 # Get the vcvarsall.bat spec for the requested platform.
239 plat_spec = PLAT_TO_VCVARS[plat_name]
--> 241 vc_env = _get_vc_env(plat_spec)
242 if not vc_env:
243 raise DistutilsPlatformError(
244 "Unable to find a compatible " "Visual Studio installation."
245 )
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\msvc.py:316, in msvc14_get_vc_env(plat_spec)
314 # Always use backport from CPython 3.8
315 try:
--> 316 return _msvc14_get_vc_env(plat_spec)
317 except distutils.errors.DistutilsPlatformError as exc:
318 _augment_exception(exc, 14.0)
File ~\anaconda3\envs\stan_env\lib\site-packages\setuptools\msvc.py:280, in _msvc14_get_vc_env(plat_spec)
275 out = subprocess.check_output(
276 'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
277 stderr=subprocess.STDOUT,
278 ).decode('utf-16le', errors='replace')
279 except subprocess.CalledProcessError as exc:
--> 280 raise distutils.errors.DistutilsPlatformError(
281 "Error executing {}".format(exc.cmd)
282 ) from exc
284 env = {
285 key.lower(): value
286 for key, _, value in
287 (line.partition('=') for line in out.splitlines())
288 if key and value
289 }
291 if vcruntime:
DistutilsPlatformError: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
If you need to use math formula, use Latex syntax:
Y \sim N(\mu, \sigma)