Parser throw a "variable does not exist" error althought the variable is declared at the top of the block


When I try to compile the model below, the parser issue a “variable ‘vector’ does not exist” error. I looked in the forum and that kind of error seems to occur when the local parameter is not declared at the top of the block. However, it’s not the case here, so I don’t understand where’s the problem.

data {
int<lower=0> N;
vector<lower=0>[N] X;
vector<lower=0>[N] Y;

parameters {
real<lower=12, upper=20> alpha;
real<lower=0> mu;
real<lower=0> sigma;

model {
vector[N] epsilon;
mu ~ normal(0, 30);
sigma ~ normal(0, 30);
for (n in 1:N) epsilon[n] = Y[n] - alpha - (X[n] * 30);
epsilon ~ normal(mu, sigma);

Many thanks in advance,


Which version of Stan are you using? That compiles fine for me in RStan 2.17.3 (the current release).

I’m using PyStan VERSION I tried with a real but I still get the same type of error.

@Bob_Carpenter Should I file a bug report?

Yes, please. It should go in the PyStan repo since it works in RStan. It may just be a problem with PyStan not being up to date enough with Stan itself, so if you could include the note I made that it works in RStan 2.17.3, that’d be helpful. Thanks!

Hi, compiles fine with PyStan

Are you on Windows? Newline markers with notepad.exe can sometimes be problematic. I would recommend using either notepad++ or atom-editor.

Raise an issue in github and we can solve the problem there.

1 Like

The Stan-to-C++ transpiler should be whitespace neutral.

Does anyone have an example of corrupted output from Notepad? I can send it to the forensics lab for text analysis (@mitzimorris literally wrote a book on the subject).

1 Like

Files created with Notepad compile fine for me but the previous model fails regardless of the editor I use.

next time I find a textfile that behaves badly I can report it.

Btw, PyStan actually reads the file in python and sends a string to C++. So reading problems could be due to python.

It used to be a problem to read textfiles in python 2 + Windows. One needed to read the file in byteformat and do the encoding manually. Something to do with utf-8 and Windows. I have not seen that problem lately.

Also notepad needs \n\r for newline and some programs can fail with this. Usually python handles transformation, but python 2 has potential for surprises.
So that is one reason I was thinking there could be some with notepad.

How did you install PyStan? (pip, pip+git, conda, source)

What is your OS? (linux, osx, win)

What is your C++ compiler? If GCC, what version?

gcc --version

First step is to uninstall your current PyStan and then reinstall it. Pip should work on all platforms.

pip install pystan

If not working, try bleeding edge from git

pip install git+

This should be fine for Stan. Unlike in Python, whitespace doesn’t have meaning in Stan.

How did you install PyStan? (pip, pip+git, conda, source)


What is your OS? (linux, osx, win)

Windows 10

What is your C++ compiler? If GCC, what version?


First step is to uninstall your current PyStan and then reinstall it.

Already tried multiple times but it didn’t solve the problem: parser doesn’t allow any type of variable inside the model block.

That does seem like a weird error.

Can you try in a new conda environment?

conda create -n stan python=3.6 m2w64-toolchain libpython cython numpy pystan -c msys2 -c conda-forge
conda activate stan

Also see your path if there are some possible locations that could interfere with stanc.

To cmd


The last thing, do you use cmd or powershell?

The new environment didn’t solve the problem.

do you use cmd or powershell?
Usually I use powershell.

Any news on this? Have the same error on conda win10

There should be an issue on the PyStan issue tracker—that’s where to track progress on fixing things.

If there isn’t such an issue, the thing to do is open one with as much of a reproducible example as possible.

Yes, please raise an issue in github. That’s the place we monitor.