How to check if cmdstan is installed

Hello, I am currently using cmdstanpy to fit a model against a bunch of data sequentially. In particular, I use a pandas .apply() method.

Inside the cmdstanpy function, I have the usual

import cmdstanpy
from cmdstanpy import CmdStanModel

and cmdstan is installed if it isn’t installed already.

My question is this: how can I determine if cmdstan is installed without calling install_cmdstan() (I am hitting the server everytime I make the install_cmdstan() call).


@mitzimorris do you know a way to do this?

Looks like there is a function validate_cmdstan_path but I don’t know if it’s exposed:

the function cmdstan_path() willl do this for you.

here’s the fine print:

  • CmdStanPy uses environment variable CMDSTAN to keep track of CmdStan install dir.
  • the default location is in hidden directory .cmdstan in user’s $HOME directory

cmdstan_path logic:
a. check if environment variable CMDSTAN has been set, if set, validate, report current value
b. look for hidden directory .cmdstan, find latest installed version, validate path, set environment variable CMDSTAN accordingly

to use something other than the latest CmdStan release - i.e., a local install built from GitHub sources - than the function set_cmdstan_path will validate and register this location accordingly.


Just for future searches: cmdstan_path() returns a ValueError when there is no cmdstan installed:

So set your try except blocks accordingly.

Thanks Mitzi (and Ben)!

1 Like

ok, that is a bit rude - would you it to return None ?

If it returns None then wouldn’t it just error later (when you try sampling or anything else using cmdstan?).

My philosophy is to fail earlier rather than later. (so a lot of computation doesn’t get wasted).


1 Like

strongly agree!

as you say, it’s just a matter of putting the call to cmdstan_path in a try except block. and while it would be only few lines of code to write the is_installed function, by not adding this to the API, the package remains simpler - easier to learn, maintain, and test.

1 Like