`cmdstan_model` call not working from command line in macbook conda environment

I recently installed cmdstan in a fresh conda environment on both my MacBook Pro and a Linux HPC I have access to, using the instructions provided here: 1 CmdStan Installation | CmdStan User’s Guide.

I’m running into issues when running cmdstan_model on my MacBook. I’m able to successfully run the exact same code on the Linux machine. From within my stan conda environment, I do the following:

cmdstan_model /path_to_stan_file/stan_file

On the Linux machine, this acts as expected, compiling the file and creating the executable. On my MacBook, I get the following error message:

realpath: illegal option -- -
usage: realpath [-q] [path ...]
make: Entering directory '/opt/homebrew/Caskroom/miniconda/base/envs/stan/bin/cmdstan'

Which is then following by the full CmdStan v2.31.0 help message. And exits out with:

make: Leaving directory '/opt/homebrew/Caskroom/miniconda/base/envs/stan/bin/cmdstan'

And the files aren’t created.

However, I am able to successfully compile and create the executable by running the following from my cmdstan directory (where make lives):

make ~/longer_path_to_stan_file/stan_file

Since the make command does work within the cmdstan directory, this issue is more of a nuisance than anything else. I lose the convenience of running cmdstan_model from where my overall project lives.

Any insight into what may be going on is much appreciated!

Additional info regarding my MacBook and CmdStan installation via conda are below:

  • Operating System: macOS Ventura 13.2.1, M1 Pro
  • CmdStan Version: 2.31.0
  • Compiler/Toolkit: clang version 14.0.6 (arm64-apple-darwin22.3.0)/GNU Make 4.3 (arm64-apple-darwin20.0.0)

Do you know what version of the realpath utility you have installed?

I suppose I could probably install something to use this from Conda, but as you note this script is mostly for convenience

It turns out that the realpath that is natively part of MacOS utils is not the same as the GNU coreutils realpath. And since MacOS’s realpath is the only thing on my laptop, it seems cmdstan called that in and spit out a MacOS realpath error, not a cmdstan error.

So I’ve downloaded GNU coreutils via homebrew (brew install coreutils), automatically installing duplicate functions with a “g” prefix. So I now have realpath and grealpath, with the latter being what I need cmdstan to use.

Homebrew says that if I want to use these “g” functions with their normal names, I can add a “gnubin” directory to my PATH with the following:
PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"

I really don’t want to do this for my entire laptop because I honestly don’t know if it will break something else in the way things operate. But I do want to do this for my cmdstan conda environment. However, I have no idea how or what file to add this line to. Would you be able to help with this?

You can make scripts which run when the environment is activated:
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-and-linux

I will also look into installing coreutils as part of the package to avoid this being an issue in the future

Rather than using realpath --relative-to=..., it might be more portable to instead try and pass the absolute path of the file. There’s a few different approaches presented in this stackoverflow post which could work

yeah, I looked into a lot of those but they honestly all seemed pretty fragile. It seems like realpath without the --relative-to would probably work to get an absolute path

Awesome - thank you for pointing me to this! I was able to incorporate the gnubin path for my stan conda environment specifically, using the resource you provided. Now, cmdstan_model works as expected! Thank you!

1 Like