Cmdstanpy fail in compiling models

Hi, I am working on advi from cmdstanpy to run a toy stan model in python using Linux. But I failed in compiling the model with lengthy error output which really confused me. I will list my workflow and part of error output. Would you mind double-checking if any part goes wrong? I really appreciate your help!
Here is the linux command part, I load gcc 11.2.0 and python first.


ml gcc/11.2.0
ml python3/3.8.10


import os
import cmdstanpy
from cmdstanpy import CmdStanModel
def main():
    stan_file = 'bernoulli.stan'
    print(stan_file)
    model = CmdStanModel(stan_file=stan_file)

    save_path = "adviResults/"
    isExist = os.path.exists(save_path)
    if not isExist:
        os.makedirs(save_path)
        print("The new directory is created!")
    data = {
     "N" : 10,
     "y" : [0,1,0,0,0,0,0,0,0,1]
    }
    fit = model.variational(data = data, output_dir = save_path)
if __name__ == '__main__':
    main()

and here is the stan code

data {
   int<lower=0> N;
   int<lower=0,upper=1> y[N];
 }
 parameters {
   real<lower=0,upper=1> theta;
 }
 model {
   theta ~ beta(1,1);  // uniform prior on interval 0,1
   y ~ bernoulli(theta);
 }

Traceback (most recent call last):
File “advi_test.py”, line 26, in
main()
File “advi_test.py”, line 11, in main
model = CmdStanModel(stan_file=stan_file)
File “/projectnb/mutsigs/venvs/mynewenv2/lib/python3.8/site-packages/cmdstanpy/model.py”, line 236, in init
self.compile(force=str(compile).lower() == ‘force’)
File “/projectnb/mutsigs/venvs/mynewenv2/lib/python3.8/site-packages/cmdstanpy/model.py”, line 563, in compile
raise ValueError(
ValueError: Failed to compile Stan model ‘/projectnb/mutsigs/mutsigsfb/haoyuefeng/FlankingBases/scripts/python/bernoulli.stan’. Console:
/share/pkg.7/gcc/11.2.0/install/bin/gcc -Wl,-L,“/usr4/ma751/fengx456/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” -Wl,-rpath,“/usr4/ma751/fengx45
6/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” /projectnb/mutsigs/mutsigsfb/haoyuefeng/FlankingBases/scripts/python/bernoulli.o -Wl,-L,“/us
r4/ma751/fengx456/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” -Wl,-rpath,“/usr4/ma751/fengx456/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” -o
/projectnb/mutsigs/mutsigsfb/haoyuefeng/FlankingBases/scripts/python/bernoulli
/lib/…/lib64/crt1.o: In function _start': (.text+0x20): undefined reference to main’

Unfortunately, I cannot reproduce this error. I use a virtual environment using conda and there are no errors. This code shows the installed packages:

import cmdstanpy as cstan
print(cstan.show_versions())

The output is:

INSTALLED VERSIONS
---------------------
python: 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:28:47) [GCC 11.3.0]
python-bits: 64
OS: Linux
OS-release: 5.15.0-67-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: es_CO.UTF-8
LOCALE: ('es_CO', 'UTF-8')
cmdstan: (2, 31)
cmdstanpy: 1.1.0
pandas: 1.5.3
xarray: None
tqdm: 4.64.1
numpy: 1.24.2

Hi, it is weird that my cmdstanpy recognized the wrong version of compiler. I loaded gcc module 11.2.0 but the output is 4.8.5 as the following

python: 3.8.10 (default, May  3 2021, 17:15:02) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
python-bits: 64
OS: Linux
OS-release: 3.10.0-1160.83.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C
LOCALE: (None, None)
cmdstan_folder: /usr4/ma751/fengx456/.cmdstan/cmdstan-2.31.0
cmdstan: (2, 31)
cmdstanpy: 1.1.0
pandas: 1.5.3
xarray: None
tqdm: 4.65.0
numpy: 1.22.4

That just indicates the version of gcc python itself was built with. What does gcc —version output after you’ve loaded all your modules?

It is gcc (GCC) 11.2.0.