Error installing Pystan 2.19 in python 3.10 with gcc 9.2.0

I am trying to install fbprophet in python. This has pystan 2.19.1.1 as a dependency. Running pip install pystan==2.19.1.1 gives me the following message:

Collecting pystan==2.19.1.1
Using cached pystan-2.19.1.1.tar.gz (16.2 MB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: Cython!=0.25.1,>=0.22 in ./py310/lib/python3.10/site-packages (from pystan==2.19.1.1) (0.29.30)
Requirement already satisfied: numpy>=1.7 in ./py310/lib/python3.10/site-packages (from pystan==2.19.1.1) (1.22.4)
Building wheels for collected packages: pystan
Building wheel for pystan (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [20700 lines of output]
    Compiling pystan/_api.pyx because it depends on /home/user/py310/lib/python3.10/site-packages/Cython/Includes/libcpp/string.pxd.
    Compiling pystan/_chains.pyx because it depends on /home/user/py310/lib/python3.10/site-packages/Cython/Includes/libcpp/vector.pxd.
    [1/2] Cythonizing pystan/_api.pyx
    [2/2] Cythonizing pystan/_chains.pyx
    running bdist_wheel
    running build
    running build_py
    creating build
.
.
.
.
.
.
    writing manifest file 'pystan.egg-info/SOURCES.txt'
    reading manifest file 'pystan.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    no previously-included directories found matching 'doc/_build'
    warning: no previously-included files matching '*.so' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '.git*' found anywhere in distribution
    warning: no previously-included files matching '*.png' found anywhere in distribution
    no previously-included directories found matching 'pystan/stan/make'
    no previously-included directories found matching 'pystan/stan/src/docs'
    no previously-included directories found matching 'pystan/stan/src/doxygen'
    no previously-included directories found matching 'pystan/stan/src/python'
    no previously-included directories found matching 'pystan/stan/src/test'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/doc'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/doxygen'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/boost_*/doc'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/boost_*/libs'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/boost_*/more'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/boost_*/status'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/boost_*/tools'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/cpplint_*'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/eigen_*/unsupported/doc'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/lib/gtest_*'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/make'
    no previously-included directories found matching 'pystan/stan/lib/stan_math/test'
    warning: no previously-included files matching '*.html' found under directory 'pystan/stan/lib/stan_math'
    warning: no previously-included files matching '*.css' found under directory 'pystan/stan/lib/stan_math'
    adding license file 'LICENSE'
    writing manifest file 'pystan.egg-info/SOURCES.txt'
    /home/user/py310/lib/python3.10/site-packages/setuptools/command/build_py.py:153: SetuptoolsDeprecationWarning:     Installing 'pystan.lookuptable' as data is deprecated, please list it in `packages`.
        !!
  
  
      ############################
      # Package would be ignored #
      ############################
      Python recognizes 'pystan.lookuptable' as an importable package,
      but it is not listed in the `packages` configuration of setuptools.
  
      'pystan.lookuptable' has been automatically added to the distribution only
      because it may contain data files, but this behavior is likely to change
      in future versions of setuptools (and therefore is considered deprecated).
  
      Please make sure that 'pystan.lookuptable' is included as a package by using
      the `packages` configuration field or the proper discovery methods
      (for example by using `find_namespace_packages(...)`/`find_namespace:`
      instead of `find_packages(...)`/`find:`).
  
      You can read more about "package discovery" and "data files" on setuptools
      documentation page.
  
  
  !!
  
    check.warn(importable)
  /home/user/py310/lib/python3.10/site-packages/setuptools/command/build_py.py:153: SetuptoolsDeprecationWarning:     Installing 'pystan.stan.lib.stan_math' as data is deprecated, please list it in `packages`.
      !!
  .
  .
  .
  .
  .
      ############################
      # Package would be ignored #
      ############################
      Python recognizes 'pystan.tests.data' as an importable package,
      but it is not listed in the `packages` configuration of setuptools.
  
      'pystan.tests.data' has been automatically added to the distribution only
      because it may contain data files, but this behavior is likely to change
      in future versions of setuptools (and therefore is considered deprecated).
  
      Please make sure that 'pystan.tests.data' is included as a package by using
      the `packages` configuration field or the proper discovery methods
      (for example by using `find_namespace_packages(...)`/`find_namespace:`
      instead of `find_packages(...)`/`find:`).
  
      You can read more about "package discovery" and "data files" on setuptools
      documentation page.
  
  
  !!
  
    check.warn(importable)
  copying pystan/_api.cpp -> build/lib.linux-x86_64-cpython-310/pystan
  copying pystan/_api.pyx -> build/lib.linux-x86_64-cpython-310/pystan
  copying pystan/_chains.cpp -> build/lib.linux-x86_64-cpython-310/pystan

  .
  .
  .
  .
  .
  .
  .
  .
  .
  .
  .

  copying pystan/tests/data/external2.stan -> build/lib.linux-x86_64-cpython-310/pystan/tests/data
  running build_ext
  building 'pystan._api' extension
  Warning: Can't read registry to find the necessary compiler setting
  Make sure that Python modules winreg, win32api or win32con are installed.
  INFO: C compiler: /home/user/gcc/bin/gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
  
  creating build/temp.linux-x86_64-cpython-310
  creating build/temp.linux-x86_64-cpython-310/pystan
  creating build/temp.linux-x86_64-cpython-310/pystan/stan
  creating build/temp.linux-x86_64-cpython-310/pystan/stan/src
  creating build/temp.linux-x86_64-cpython-310/pystan/stan/src/stan
  creating build/temp.linux-x86_64-cpython-310/pystan/stan/src/stan/lang
  creating build/temp.linux-x86_64-cpython-310/pystan/stan/src/stan/lang/grammars
  INFO: compile options: '-DBOOST_DISABLE_ASSERTS -DBOOST_NO_DECLTYPE -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_RESULT_OF_USE_TR1 -DFUSION_MAX_VECTOR_SIZE=12 -I./pystan -Ipystan/stan/src -Ipystan/stan/lib/stan_math/ -Ipystan/stan/lib/stan_math/lib/eigen_3.3.3 -Ipystan/stan/lib/stan_math/lib/boost_1.69.0 -Ipystan/stan/lib/stan_math/lib/sundials_4.1.0/include -I/home/user/py310/include/python3.10 -c'
  extra options: '-Os -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++1y'
  INFO: gcc: pystan/stan/src/stan/lang/ast_def.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/bare_type_grammar_inst.cpp
  INFO: gcc: pystan/_api.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/block_var_decls_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/expression07_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/expression_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/functions_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/indexes_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/local_var_decls_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/program_grammar_inst.cpp
  In file included from pystan/stan/src/stan/lang/generator/expression_visgen.hpp:7,
                   from pystan/stan/src/stan/lang/generator/generate_expression.hpp:5,
                   from pystan/stan/src/stan/lang/generator/write_begin_all_dims_col_maj_loop.hpp:6,
                   from pystan/stan/src/stan/lang/generator.hpp:10,
                   from pystan/stan/src/stan/lang/compiler.hpp:6,
                   from pystan/stanc.hpp:2,
                   from pystan/_api.cpp:784:
  pystan/stan/src/stan/lang/generator/generate_indexed_expr.hpp: In instantiation of ‘void stan::lang::generate_indexed_expr(const string&, const std::vector<stan::lang::expression>&, stan::lang::bare_expr_type, bool, std::ostream&) [with bool isLHS = false; std::string = std::__cxx11::basic_string<char>; std::ostream = std::basic_ostream<char>]’:
  pystan/stan/src/stan/lang/generator/expression_visgen.hpp:117:54:   required from here
  pystan/stan/src/stan/lang/generator/generate_indexed_expr.hpp:44:35: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<stan::lang::expression>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
     44 |           && base_type.num_dims() == indexes.size()) {
        |              ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
  INFO: gcc: pystan/stan/src/stan/lang/grammars/semantic_actions_def.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/statement_2_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/statement_grammar_inst.cpp
  INFO: gcc: pystan/stan/src/stan/lang/grammars/term_grammar_inst.cpp
  In file included from pystan/stan/src/stan/lang/ast_def.cpp:97:
  pystan/stan/src/stan/lang/ast/sigs/function_signatures_def.hpp: In constructor ‘stan::lang::function_signatures::function_signatures()’:
  pystan/stan/src/stan/lang/ast/sigs/function_signatures_def.hpp:484:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without
    484 |     function_signatures::function_signatures() {
        |     ^~~~~~~~~~~~~~~~~~~
  INFO: gcc: pystan/stan/src/stan/lang/grammars/whitespace_grammar_inst.cpp
  INFO: /home/user/gcc/bin/g++ -shared build/temp.linux-x86_64-cpython-310/pystan/_api.o build/temp.linux-x86_64-cpython-310/pystan/stan/src/stan/lang/ast_def.o build/temp.linux-x86_64-cpython-310/pystan/stan/src/stan/lang/grammars/bare_type_grammar_inst.o build/temp.linux-x86_64-cpython-
  .
  .
  .

  pystan/stan/lib/stan_math/lib/eigen_3.3.3/Eigen/src/Core/AssignEvaluator.h:86:63: warning: enum constant in boolean context [-Wint-in-bool-context]
     86 |     MayLinearVectorize = bool(MightVectorize) && MayLinearize && DstHasDirectAccess
        |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
  In file included from pystan/stan/lib/stan_math/lib/eigen_3.3.3/Eigen/Core:420,
                   from pystan/stan/lib/stan_math/lib/eigen_3.3.3/Eigen/Dense:1,
                   from pystan/stan/lib/stan_math/stan/math/prim/mat/fun/Eigen.hpp:4,
                   from pystan/stan/lib/stan_math/stan/math/prim/mat/fun/autocovariance.hpp:4,
                   from pystan/_chains.cpp:771:
  pystan/stan/lib/stan_math/lib/eigen_3.3.3/Eigen/src/Core/AssignEvaluator.h:90:50: warning: enum constant in boolean context [-Wint-in-bool-context]
     90 |     MaySliceVectorize  = bool(MightVectorize) && bool(DstHasDirectAccess)
        |                                                  ^~~~~~~~~~~~~~~~~~~~~~~~
  INFO: /home/user/gcc/bin/g++ -shared build/temp.linux-x86_64-cpython-310/pystan/_chains.o -o build/lib.linux-x86_64-cpython-310/pystan/_chains.cpython-310-x86_64-linux-gnu.so
  building 'pystan._misc' extension
  INFO: C compiler: /home/user/gcc/bin/gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
  
  INFO: compile options: '-I/home/user/py310/include/python3.10 -c'
  extra options: '-Os -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++1y'
  INFO: gcc: pystan/_misc.cpp
  In file included from /home/user/py310/include/python3.10/Python.h:74,
                   from pystan/_misc.cpp:24:
  pystan/_misc.cpp: In function ‘void __pyx_tp_dealloc_array(PyObject*)’:
  /home/user/py310/include/python3.10/object.h:133:58: error: lvalue required as increment operand
    133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
        |                                                          ^
  pystan/_misc.cpp:15723:7: note: in expansion of macro ‘Py_REFCNT’
  15723 |     ++Py_REFCNT(o);
        |       ^~~~~~~~~
  /home/user/py310/include/python3.10/object.h:133:58: error: lvalue required as decrement operand
    133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
        |                                                          ^
  pystan/_misc.cpp:15725:7: note: in expansion of macro ‘Py_REFCNT’
  15725 |     --Py_REFCNT(o);
        |       ^~~~~~~~~
  pystan/_misc.cpp: In function ‘void __pyx_tp_dealloc_memoryview(PyObject*)’:
  /home/user/py310/include/python3.10/object.h:133:58: error: lvalue required as increment operand
    133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
        |                                                          ^
  pystan/_misc.cpp:16018:7: note: in expansion of macro ‘Py_REFCNT’
  16018 |     ++Py_REFCNT(o);
        |       ^~~~~~~~~
  /home/user/py310/include/python3.10/object.h:133:58: error: lvalue required as decrement operand
    133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
        |                                                          ^
  pystan/_misc.cpp:16020:7: note: in expansion of macro ‘Py_REFCNT’
  16020 |     --Py_REFCNT(o);
        |       ^~~~~~~~~
  pystan/_misc.cpp: In function ‘void __pyx_tp_dealloc__memoryviewslice(PyObject*)’:
  /home/user/py310/include/python3.10/object.h:133:58: error: lvalue required as increment operand
    133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
        |                                                          ^
  pystan/_misc.cpp:16260:7: note: in expansion of macro ‘Py_REFCNT’
  16260 |     ++Py_REFCNT(o);
        |       ^~~~~~~~~
  /home/user/py310/include/python3.10/object.h:133:58: error: lvalue required as decrement operand
    133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
        |                                                          ^
  pystan/_misc.cpp:16262:7: note: in expansion of macro ‘Py_REFCNT’
  16262 |     --Py_REFCNT(o);
        |       ^~~~~~~~~
  In file included from /home/user/py310/include/python3.10/unicodeobject.h:1046,
                   from /home/user/py310/include/python3.10/Python.h:83,
                   from pystan/_misc.cpp:24:
  pystan/_misc.cpp: In function ‘int __Pyx_ParseOptionalKeywords(PyObject*, PyObject***, PyObject*, PyObject**, Py_ssize_t, const char*)’:
  /home/user/py310/include/python3.10/cpython/unicodeobject.h:451:75: warning: ‘Py_ssize_t _PyUnicode_get_wstr_length(PyObject*)’ is deprecated [-Wdeprecated-declarations]
    451 | #define PyUnicode_WSTR_LENGTH(op) _PyUnicode_get_wstr_length((PyObject*)op)
        |                                                                           ^
  /home/user/py310/include/python3.10/cpython/unicodeobject.h:261:7: note: in expansion of macro ‘PyUnicode_WSTR_LENGTH’
    261 |       PyUnicode_WSTR_LENGTH(op) :                    \
        |       ^~~~~~~~~~~~~~~~~~~~~
  pystan/_misc.cpp:18078:22: note: in expansion of macro ‘PyUnicode_GET_SIZE’
  18078 |                     (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
        |                      ^~~~~~~~~~~~~~~~~~
  /home/user/py310/include/python3.10/cpython/unicodeobject.h:446:26: note: declared here
    446 | static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) {
        |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
  /home/user/py310/include/python3.10/cpython/unicodeobject.h:451:75: warning: ‘Py_ssize_t _PyUnicode_get_wstr_length(PyObject*)’ is deprecated [-Wdeprecated-declarations]
    451 | #define PyUnicode_WSTR_LENGTH(op) _PyUnicode_get_wstr_length((PyObject*)op)
        |                                                                           ^
  /home/user/py310/include/python3.10/cpython/unicodeobject.h:261:7: note: in expansion of macro ‘PyUnicode_WSTR_LENGTH’
    261 |       PyUnicode_WSTR_LENGTH(op) :                    \
        |       ^~~~~~~~~~~~~~~~~~~~~
  pystan/_misc.cpp:18078:22: note: in expansion of macro ‘PyUnicode_GET_SIZE’
  18078 |                     (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
        |                      ^~~~~~~~~~~~~~~~~~
  /home/user/py310/include/python3.10/cpython/unicodeobject.h:446:26: note: declared here
    446 | static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) {
        |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
  pystan/_misc.cpp:18596:45: warning: ‘PyObject* PyUnicode_FromUnicode(const Py_UNICODE*, Py_ssize_t)’ is deprecated [-Wdeprecated-declarations]
  18596 |         return PyUnicode_FromUnicode(NULL, 0);
        |                                             ^
  In file included from /home/user/py310/include/python3.10/unicodeobject.h:1046,
                   from /home/user/py310/include/python3.10/Python.h:83,
                   from pystan/_misc.cpp:24:
  /home/user/py310/include/python3.10/cpython/unicodeobject.h:551:42: note: declared here
    551 | Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
        |                                          ^~~~~~~~~~~~~~~~~~~~~
  error: Command "/home/user/gcc/bin/gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/user/py310/include/python3.10 -c pystan/_misc.cpp -o build/temp.linux-x86_64-cpython-310/pystan/_misc.o -Os -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++1y" failed with exit status 1
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pystan
Running setup.py clean for pystan
Failed to build pystan

Googling around gives me the impression that there may be a mismatch between my c++ compiler version, and the version that pystan 2.19.1.1 expects. Let me add that pystan 3.4.0 install just fine, but is incompatible with fbprophet.
My system specifications are:

Operating System: CentOS Linux 7 (Core)
Python Version : Python 3.10
PyStan Version: 2.19.1.1
Compiler/Toolkit: GCC 9.2.0

Should I be using a different version of python? or gcc?

Thank you!

Maybe first try updating setuptools and if that doesn’t work, try to install a version from 1 year ago (check pypi for the version)

I have upgraded to setuptools-62.4.0, and I still get the error. I noticed that the pystan versions from a year ago are 3.0.0 and above, however the fbprophet python package checks specifically checks for version 2.19.1.1 (I don’t know of a way to point it to another pystan version).

In particular, I noticed the following error at several points in the output logs:
In file included from /home/user/py310/include/python3.10/Python.h:74,
from pystan/_misc.cpp:24:
pystan/_misc.cpp: In function ‘void __pyx_tp_dealloc_array(PyObject*)’:
/home/user/py310/include/python3.10/object.h:133:58: error: lvalue required as increment operand
133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
| ^

Older setuptools

Setuptools: 62.6.0
I still get the error. Is there a specific version you might recommend?

Hmm, I think I have an idea what is the problem, I think there are some cython things done already in tar file.

I recommend you install directly from pystan2 repo

pip install git+https://github.com/stan-dev/pystan2.git@master

This solved the problem! Thanks so much!!

Throws an error : File name too long while generating.
Don’t know if this solution is still viable.

OS : Windows
Python : 3.10

For that I recommend enabling long paths (check google how)

got error while installing pystan==2.19.1.1 showing building wheel failed

Dear, ahartikainen.
Same problem is as of now 2024, trying to install 2.19.1.1, but nothing works, gcc and clang versions are up to date, but the installation still gives error, even while installing from repo. I have looked at repo and saw that it had been archived. Any solutions?
PS. Again the same thing is for me, the package which I need to use uses version 2.19.1.1 only.

Which package is this?

pystan

Sorry, I meant what package requires pystan2

simpleconjoint in Python

You probably need old python (3.8?). But really package should be updated to support either pystan 3 or cmdstanpy.