stan-dev / pystan2

PyStan, the Python interface to Stan
GNU General Public License v3.0
920 stars 189 forks source link

ImportError when compiling model on Ubuntu with Anaconda #269

Closed jonasbusk closed 7 years ago

jonasbusk commented 7 years ago

Summary:

Stan fails with an ImportError when compiling the C++ code for a model on Ubuntu with Anaconda.

Description:

I've pip installed pystan and can import pystan in Python without errors. But when compiling a Stan model (for example the eight schools example), I get an ImportError.

Using pystan on my Mac with Anaconda in a similar way works fine.

Reproducible Steps:

  1. $ conda create -n pystan
  2. $ source activate pystan
  3. $ pip install pystan
  4. $ python eight_schools.py

Current Output:

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_95013624776d537c3cd7cd4d641c30e0 NOW.
Traceback (most recent call last):
  File "eight_schools.py", line 30, in <module>
    iter=1000, chains=4)
  File "/home/jonas/.conda/envs/pystan/lib/python2.7/site-packages/pystan/api.py", line 372, in stan
    verbose=verbose)
  File "/home/jonas/.conda/envs/pystan/lib/python2.7/site-packages/pystan/model.py", line 316, in __init__
    self.module = load_module(self.module_name, lib_dir)
  File "/home/jonas/.conda/envs/pystan/lib/python2.7/site-packages/pystan/model.py", line 55, in load_module
    return imp.load_module(module_name, *module_info)
ImportError: /tmp/tmpLiJgvA/stanfit4anon_model_95013624776d537c3cd7cd4d641c30e0_5096100179209156203.so: undefined symbol: _ZTVNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE

Expected Output:

No errors.

PyStan Version:

'2.12.0.0'

Python Version:

Python 2.7.12 :: Anaconda 4.2.0 (64-bit)

Operating System:

Ubuntu 16.04 LTS

gawhitaker commented 7 years ago

I have the same issue, wondering if it's a recent problem

ariddell commented 7 years ago

Interesting. The version on PyPI hasn't changed. Can you try just doing this and seeing if it fails during the compilation step?

import pystan

model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code, verbose=True)
jonasbusk commented 7 years ago

Thank you for your response.

Running your code produces the following output and at the end fails with an ImportError:

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_5944b02c79788fa0db5b3a93728ca2bf NOW.
INFO:pystan:OS: linux2, Python: 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)], Cython 0.24.1
Compiling /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.pyx because it changed.
[1/1] Cythonizing /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.pyx
building 'stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586' extension
creating /tmp/tmpeLil5A/tmp
creating /tmp/tmpeLil5A/tmp/tmpeLil5A
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I/tmp/tmpeLil5A -I/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan -I/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/src -I/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0 -I/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/eigen_3.2.9 -I/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0 -I/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/cvodes_2.8.2/include -I/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/numpy/core/include -I/home/jonas/anaconda2/envs/pystan/include/python2.7 -c /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp -o /tmp/tmpeLil5A/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.o -O2 -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:339:
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
In file included from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/base.hpp:28:0,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array.hpp:21,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/numeric/odeint/util/multi_array_adaption.hpp:29,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/numeric/odeint.hpp:61,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/arr/functor/integrate_ode_rk45.hpp:13,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/arr.hpp:36,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/mat.hpp:235,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/mix/mat.hpp:12,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/src/stan/model/util.hpp:5,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan_fit.hpp:18,
                 from /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:343:
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp: In static member function ‘static void boost::multi_array_concepts::detail::idgen_helper<N>::call(Array&, const IdxGen&, Call_Type)’:
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:42:43: warning: typedef ‘index_range’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:43:37: warning: typedef ‘index’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp: In static member function ‘static void boost::multi_array_concepts::detail::idgen_helper<0ul>::call(Array&, const IdxGen&, Call_Type)’:
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:53:43: warning: typedef ‘index_range’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:54:37: warning: typedef ‘index’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp: In function ‘PyObject* __pyx_pf_71stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586_2_call_sampler(PyObject*, PyObject*, PyObject*, PyObject*)’:
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:8412:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     __pyx_t_12 = ((__pyx_t_9 != __pyx_v_fitptr->param_names_oi().size()) != 0);
                              ^
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp: In function ‘std::vector<long unsigned int> __pyx_convert_vector_from_py_size_t(PyObject*)’:
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:19293:77: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     __pyx_t_5 = __Pyx_PyInt_As_size_t(__pyx_v_item); if (unlikely(__pyx_t_5 == -1L && PyErr_Occurred())) __PYX_ERR(2, 52, __pyx_L1_error)
                                                                             ^
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:542:43: note: in definition of macro ‘unlikely’
   #define unlikely(x) __builtin_expect(!!(x), 0)
                                           ^
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp: In function ‘std::vector<unsigned int> __pyx_convert_vector_from_py_unsigned_int(PyObject*)’:
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:19875:83: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     __pyx_t_5 = __Pyx_PyInt_As_unsigned_int(__pyx_v_item); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) __PYX_ERR(2, 52, __pyx_L1_error)
                                                                                   ^
/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:542:43: note: in definition of macro ‘unlikely’
   #define unlikely(x) __builtin_expect(!!(x), 0)
                                           ^
In file included from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/rev/core/operator_unary_plus.hpp:7:0,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/rev/core.hpp:34,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/mix/mat.hpp:8,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/src/stan/model/util.hpp:5,
                 from /home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan_fit.hpp:18,
                 from /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.cpp:343:
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/scal/fun/constants.hpp: At global scope:
/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/scal/fun/constants.hpp:65:18: warning: ‘stan::math::NEGATIVE_EPSILON’ defined but not used [-Wunused-variable]
     const double NEGATIVE_EPSILON
                  ^
g++ -pthread -shared -L/home/jonas/anaconda2/envs/pystan/lib -Wl,-rpath=/home/jonas/anaconda2/envs/pystan/lib,--no-as-needed /tmp/tmpeLil5A/tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.o -L/home/jonas/anaconda2/envs/pystan/lib -lpython2.7 -o /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.so
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    model = pystan.StanModel(model_code=model_code, verbose=True)
  File "/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/model.py", line 316, in __init__
    self.module = load_module(self.module_name, lib_dir)
  File "/home/jonas/anaconda2/envs/pystan/lib/python2.7/site-packages/pystan/model.py", line 55, in load_module
    return imp.load_module(module_name, *module_info)
ImportError: /tmp/tmpeLil5A/stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_7654584011646863586.so: undefined symbol: _ZTVNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE
ariddell commented 7 years ago

I'm not sure what's going on. This isn't an error I've seen before.

I'm not encountering any problems like this when I use Python 2.7.12 on Linux. Does it happen with Python 3 (Anaconda latest)? The import machinery is rather different in Python 2.7 vs. Python 3.5.

gawhitaker commented 7 years ago

I realise this is not an elegant solution, but I managed to get things to work by removing the current version of Anaconda, and backdating to Anaconda 4.0.0 (then reinstalling PyStan etc)

Auerilas commented 7 years ago

I am having a near identical issue. I just switched from OS X to Linux Mint 18.

Reproducible example:

import numpy as np
import pystan as pyst
/home/auerilas/anaconda3/lib/python3.5/site-packages/Cython/Distutils/old_build_ext.py:30: UserWarning: Cython.Distutils.old_build_ext does not properly handle dep
endencies and is deprecated.
  "Cython.Distutils.old_build_ext does not properly handle dependencies "

And then:

X = np.random.normal(size=100)

mod1 = """
data{
    int<lower=0> N;
    vector[N] y;
}
parameters{
    real mu;
    real<lower=0> sd1;
}
model{
    y ~ normal(mu, sd1);
}
"""
compM = pyst.StanModel(model_code=mod1, verbose=True)

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_ce232edb1c470d8f38144459339cca7d NOW.
INFO:pystan:OS: linux, Python: 3.5.2 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)], Cython 0.25.1
Compiling /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.pyx because it changed.
[1/1] Cythonizing /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.pyx
building 'stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709' extension
creating /tmp/tmpmn3ho9p1/tmp
creating /tmp/tmpmn3ho9p1/tmp/tmpmn3ho9p1
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I/tmp/tm
pmn3ho9p1 -I/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan -I/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/src -I/home/auerilas/ana
conda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0 -I/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/eig
en_3.2.9 -I/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0 -I/home/auerilas/anaconda3/lib/python3.5/site-pac
kages/pystan/stan/lib/stan_math_2.12.0/lib/cvodes_2.8.2/include -I/home/auerilas/anaconda3/lib/python3.5/site-packages/numpy/core/include -I/home/auerilas/anaconda
3/include/python3.5m -c /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp -o /tmp/tmpmn3ho9p1/tmp/tmpmn3ho9p1/stanfit4an
on_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.o -O2 -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from /home/auerilas/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:473:
/home/auerilas/anaconda3/lib/python3.5/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable
 it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
In file included from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/base.hpp:28:0,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array.hpp:21,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/numeric/odeint/util/multi_array_

adaption.hpp:29,                                                                                                                                           [52/515]
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/numeric/odeint.hpp:61,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/arr/functor/integrate_ode_rk45.hpp:13,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/arr.hpp:36,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/mat.hpp:235,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/mix/mat.hpp:12,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/src/stan/model/util.hpp:5,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan_fit.hpp:18,
                 from /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:477:
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp: In static member funct
ion ‘static void boost::multi_array_concepts::detail::idgen_helper<N>::call(Array&, const IdxGen&, Call_Type)’:
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:42:43: warning: typedef
 ‘index_range’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:43:37: warning: typedef
 ‘index’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp: In static member funct
ion ‘static void boost::multi_array_concepts::detail::idgen_helper<0ul>::call(Array&, const IdxGen&, Call_Type)’:
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:53:43: warning: typedef
 ‘index_range’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/lib/boost_1.60.0/boost/multi_array/concept_checks.hpp:54:37: warning: typedef
 ‘index’ locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp: In function ‘PyObject* __pyx_pf_71stanfit4anon_model_ce232edb1c470d8f
38144459339cca7d_5834015054786197709_2_call_sampler(PyObject*, PyObject*, PyObject*, PyObject*)’:
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:8764:30: warning: comparison between signed and unsigned integer expre
ssions [-Wsign-compare]
     __pyx_t_12 = ((__pyx_t_9 != __pyx_v_fitptr->param_names_oi().size()) != 0);
                              ^
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp: In function ‘std::vector<long unsigned int> __pyx_convert_vector_from
_py_size_t(PyObject*)’:
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:20669:77: warning: comparison between signed and unsigned integer expr
essions [-Wsign-compare]
     __pyx_t_5 = __Pyx_PyInt_As_size_t(__pyx_v_item); if (unlikely(__pyx_t_5 == -1L && PyErr_Occurred())) __PYX_ERR(2, 52, __pyx_L1_error)
                                                                             ^
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:676:43: note: in definition of macro ‘unlikely’
   #define unlikely(x) __builtin_expect(!!(x), 0)
                                           ^
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp: In function ‘std::vector<unsigned int> __pyx_convert_vector_from_py_u
nsigned_int(PyObject*)’:
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:21251:83: warning: comparison between signed and unsigned integer expr
essions [-Wsign-compare]
     __pyx_t_5 = __Pyx_PyInt_As_unsigned_int(__pyx_v_item); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) __PYX_ERR(2, 52, __pyx_L1_error)
                                                                                   ^
/tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:676:43: note: in definition of macro ‘unlikely’
   #define unlikely(x) __builtin_expect(!!(x), 0)

In file included from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/rev/core/operator_unary_plus.hpp:7:0,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/rev/core.hpp:34,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/mix/mat.hpp:8,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/src/stan/model/util.hpp:5,
                 from /home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan_fit.hpp:18,
                 from /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpp:477:
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/scal/fun/constants.hpp: At global scope:
/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/stan/lib/stan_math_2.12.0/stan/math/prim/scal/fun/constants.hpp:65:18: warning: ‘stan::math::NEGATIVE_E
PSILON’ defined but not used [-Wunused-variable]
     const double NEGATIVE_EPSILON
                  ^
g++ -pthread -shared -L/home/auerilas/anaconda3/lib -Wl,-rpath=/home/auerilas/anaconda3/lib,--no-as-needed /tmp/tmpmn3ho9p1/tmp/tmpmn3ho9p1/stanfit4anon_model_ce23
2edb1c470d8f38144459339cca7d_5834015054786197709.o -L/home/auerilas/anaconda3/lib -lpython3.5m -o /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cc
a7d_5834015054786197709.cpython-35m-x86_64-linux-gnu.so
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-43dec5d31308> in <module>()
----> 1 compM = pyst.StanModel(model_code=mod1, verbose=True)

/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/model.py in __init__(self, file, charset, model_name, model_code, stanc_ret, boost_lib, eigen_lib, verb
ose, obfuscate_model_name, extra_compile_args)
    314                 os.dup2(orig_stderr, sys.stderr.fileno())
    315 
--> 316         self.module = load_module(self.module_name, lib_dir)
    317         self.module_filename = os.path.basename(self.module.__file__)
    318         # once the module is in memory, we no longer need the file on disk

/home/auerilas/anaconda3/lib/python3.5/site-packages/pystan/model.py in load_module(module_name, module_path)
     49         # Python 3
     50         loader = importlib.find_loader(module_name, [module_path])
---> 51         return loader.load_module()
     52     else:
     53         # Python 2.7

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap_external.py in _check_name_wrapper(self, name, *args, **kwargs)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap_external.py in load_module(self, fullname)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap_external.py in load_module(self, fullname)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap.py in _load_module_shim(self, fullname)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap.py in _load(spec)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap.py in _load_unlocked(spec)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap.py in module_from_spec(spec)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap_external.py in create_module(self, spec)

/home/auerilas/anaconda3/lib/python3.5/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: /tmp/tmpmn3ho9p1/stanfit4anon_model_ce232edb1c470d8f38144459339cca7d_5834015054786197709.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZTVNSt7__
cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE

I hope this helps. It might have something to do with Cython using an old version?

Auerilas commented 7 years ago

I can also confirm that the downgrade to Anaconda 4.0.0 works. Or it did for me.

ariddell commented 7 years ago

Could be a Cython issue. What version of Cython does this new Anaconda use?

Auerilas commented 7 years ago

I think Anaconda 4.4 uses Conda 0.24, and when I installed pystan it updated Cython to 0.25

Currently I'm using Cython 0.23.4 and it works fine.

On 11/15/2016 06:32 AM, Allen Riddell wrote:

Could be a Cython issue. What version of Cython does this new Anaconda use?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stan-dev/pystan/issues/269#issuecomment-260641821, or mute the thread https://github.com/notifications/unsubscribe-auth/AI8CShhsUIl_41w5lUViSe5ngC0KudUwks5q-bR0gaJpZM4KtaHG.

Nathan Lemoine

Research Scientist I USDA NIFA-AFRI Postdoctoral Fellow

Colorado State University Department of Biology Graduate Degree Program in Ecology

ariddell commented 7 years ago

Yup. I'm hitting this with Cython 0.25.

ariddell commented 7 years ago

Looks like it might be related to #271 although I don't know how. I created a new issue #272 on the off chance that this is some unrelated problem.

mhashemi0873 commented 7 years ago

I have the same problem. I used: Python 2.7.12 :: Anaconda custom (64-bit) Ubuntu 16.04 LTS

I run the ''eight schools'' example , I have tried all the installation guidelines (pip, github,...), with python 2.7 and 3.5, executing from /home, /tmp/,... but I get the following error:

runfile('/tmp/eightschools.py', wdir='/tmp') INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_95013624776d537c3cd7cd4d641c30e0 NOW. Traceback (most recent call last):

File "", line 1, in runfile('/tmp/eightschools.py', wdir='/tmp')

File "/home/meysam/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile execfile(filename, namespace)

File "/home/meysam/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile builtins.execfile(filename, *where)

File "/tmp/eightschools.py", line 37, in iter=1000, chains=4)

File "/home/meysam/anaconda2/lib/python2.7/site-packages/pystan/api.py", line 368, in stan verbose=verbose)

File "/home/meysam/anaconda2/lib/python2.7/site-packages/pystan/model.py", line 315, in init self.module = load_module(module_name, lib_dir)

File "/home/meysam/anaconda2/lib/python2.7/site-packages/pystan/model.py", line 54, in load_module return imp.load_module(module_name, *module_info)

ImportError: /tmp/tmpLK2qQa/pystan/stanfit4anon_model_95013624776d537c3cd7cd4d641c30e0_724952c86beb130db392f6b01aa1ef05.so: undefined symbol: _ZNSt8ios_base7failureB5cxx11D1Ev

Interestingly, in Mac OS I don't get any error. Thanks a lot in advance for any help. Best, Meysam

mhashemi0873 commented 7 years ago

I tried with Jupyter and I get the following error:

ImportError Traceback (most recent call last)

in () 27 28 fit = pystan.stan(model_code=schools_code, data=schools_dat, ---> 29 iter=1000, chains=4) /home/meysam/anaconda2/lib/python2.7/site-packages/pystan/api.pyc in stan(file, model_name, model_code, fit, data, pars, chains, iter, warmup, thin, init, seed, algorithm, control, sample_file, diagnostic_file, verbose, boost_lib, eigen_lib, n_jobs, **kwargs) 366 m = StanModel(file=file, model_name=model_name, model_code=model_code, 367 boost_lib=boost_lib, eigen_lib=eigen_lib, --> 368 verbose=verbose) 369 # check that arguments in kwargs are valid 370 valid_args = {"chain_id", "init_r", "test_grad", "append_samples", "enable_random_init", /home/meysam/anaconda2/lib/python2.7/site-packages/pystan/model.pyc in __init__(self, file, charset, model_name, model_code, stanc_ret, boost_lib, eigen_lib, verbose, obfuscate_model_name) 313 os.dup2(orig_stderr, sys.stderr.fileno()) 314 --> 315 self.module = load_module(module_name, lib_dir) 316 self.fit_class = getattr(self.module, "StanFit4Model") 317 /home/meysam/anaconda2/lib/python2.7/site-packages/pystan/model.pyc in load_module(module_name, module_path) 52 # Python 2.7 53 module_info = imp.find_module(module_name, [module_path]) ---> 54 return imp.load_module(module_name, *module_info) 55 56 ImportError: /tmp/tmpLwXZPP/pystan/stanfit4anon_model_95013624776d537c3cd7cd4d641c30e0_724952c86beb130db392f6b01aa1ef05.so: undefined symbol: _ZNSt8ios_base7failureB5cxx11D1Ev
jbao commented 7 years ago

A bit late in the discussion, but I also had a similar problem, and conda install pystan instead of pip install seems to fix the issue for me.

mhashemi0873 commented 7 years ago

Thanks a lot for your hint. I try this.

ariddell commented 7 years ago

Fixed with new version of Cython.

jonasbusk commented 7 years ago

Did anyone get pystan to work with Anaconda 4.2.0 (latest)?

By the way, conda install pystan will install pystan 2.8.0.0 while pip install pystan will install pystan 2.14.0.0.

Python 2.7.12 :: Anaconda 4.2.0 (64-bit) Ubuntu 16.04 LTS

ariddell commented 7 years ago

Thanks for the report @jonasbusk . Help me create some new issues here if you have a moment: (1) a fresh install with Anaconda should work with PyStan 2.14.0.0 and (2) conda install pystan needs to be fixed (if it can be fixed).

mhashemi0873 commented 7 years ago

I tried with Python 3.5.2 : : Anaconda 4.2.0 (64-bit) and Cython 0.25.2 and unfortunately I received the same error as before. (I tried with both install method: conda install pystan and pip install pystan).

Python 3.5.2 : : Anaconda 4.2.0 (64-bit) Cython version 0.25.2 Ubuntu 16.04 LTS

ariddell commented 7 years ago

This looks like an Anaconda bug. See the discussion on #292.