stan-dev / pystan2

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

CompileError: command 'gcc' failed with exit status 1 #470

Closed elena-zamfir closed 5 years ago

elena-zamfir commented 6 years ago

Summary:

I have just upgraded pystan, which was working fine, with pip install pystan --upgrade. Now it's not compiling models any more. It gives an error about gcc.

Description:

I have just upgraded pystan to version 2.17.1.0 It no longer compiles modesl, I get the error message: INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_cbe9cd2f1e5ab5d1c7cce1f23ca970b4 NOW. Traceback (most recent call last): File "/nfs/nhome/live/elena/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 27, in sm = pystan.StanModel(model_code=schools_code) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/site-packages/pystan/model.py", line 313, in init build_extension.run() File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/command/build_ext.py", line 448, in build_extensions self.build_extension(ext) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/command/build_ext.py", line 498, in build_extension depends=ext.depends) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/unixccompiler.py", line 124, in _compile raise CompileError, msg CompileError: command 'gcc' failed with exit status 1

Reproducible Steps:

schools_code = """ data { int J; // number of schools real y[J]; // estimated treatment effects real sigma[J]; // s.e. of effect estimates } parameters { real mu; real tau; real eta[J]; } transformed parameters { real theta[J]; for (j in 1:J) theta[j] = mu + tau * eta[j]; } model { eta ~ normal(0, 1); y ~ normal(theta, sigma); } """

schools_dat = {'J': 8, 'y': [28, 8, -3, 7, -1, 1, 18, 12], 'sigma': [15, 10, 16, 11, 9, 11, 10, 18]}

sm = pystan.StanModel(model_code=schools_code)

Current Output:

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_cbe9cd2f1e5ab5d1c7cce1f23ca970b4 NOW. Traceback (most recent call last): File "/nfs/nhome/live/elena/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 27, in sm = pystan.StanModel(model_code=schools_code) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/site-packages/pystan/model.py", line 313, in init build_extension.run() File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/command/build_ext.py", line 448, in build_extensions self.build_extension(ext) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/command/build_ext.py", line 498, in build_extension depends=ext.depends) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/nfs/nhome/live/elena/anaconda/lib/python2.7/distutils/unixccompiler.py", line 124, in _compile raise CompileError, msg CompileError: command 'gcc' failed with exit status 1

PyStan Version: 2.17.1.0

Python Version:2.7.12 |Anaconda 2.2.0 (64-bit)| (default, Jul 2 2016, 17:42:40)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

Operating System: Ubuntu 16.04.3 LTS

ahartikainen commented 6 years ago

It might be some problem between gcc 4.x and gcc 5.y. Can you try to create a new conda-env and run your model in there

conda create -n stan python=2.7 numpy cython
source activate stan
pip install pystan

edit. bumpy --> numpy

elena-zamfir commented 6 years ago

Thank you for your reply! I've just tried this, now I get a g++ failed with exit status 1 error: (I first copy pasted the command you sent, but I don't have bumpy, I assumed you meant numpy. )

(stan) elena@u236d:~$ python Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55) [GCC 7.2.0] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import pystan schools_code = """ ... data { ... int J; // number of schools ... real y[J]; // estimated treatment effects ... real sigma[J]; // s.e. of effect estimates ... } ... parameters { ... real mu; ... real tau; ... real eta[J]; ... } ... transformed parameters { ... real theta[J]; ... for (j in 1:J) ... theta[j] = mu + tau * eta[j]; ... } ... model { ... eta ~ normal(0, 1); ... y ~ normal(theta, sigma); ... } ... """

schools_dat = {'J': 8, ... 'y': [28, 8, -3, 7, -1, 1, 18, 12], ... 'sigma': [15, 10, 16, 11, 9, 11, 10, 18]}

sm = pystan.StanModel(model_code=schools_code) INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_cbe9cd2f1e5ab5d1c7cce1f23ca970b4 NOW. Traceback (most recent call last): File "", line 1, in File "/nfs/nhome/live/elena/anaconda/envs/stan/lib/python2.7/site-packages/pystan/model.py", line 313, in init build_extension.run() File "/nfs/nhome/live/elena/anaconda/envs/stan/lib/python2.7/distutils/command/build_ext.py", line 340, in run self.build_extensions() File "/nfs/nhome/live/elena/anaconda/envs/stan/lib/python2.7/distutils/command/build_ext.py", line 449, in build_extensions self.build_extension(ext) File "/nfs/nhome/live/elena/anaconda/envs/stan/lib/python2.7/distutils/command/build_ext.py", line 531, in build_extension target_lang=language) File "/nfs/nhome/live/elena/anaconda/envs/stan/lib/python2.7/distutils/ccompiler.py", line 691, in link_shared_object extra_preargs, extra_postargs, build_temp, target_lang) File "/nfs/nhome/live/elena/anaconda/envs/stan/lib/python2.7/distutils/unixccompiler.py", line 203, in link raise LinkError, msg distutils.errors.LinkError: command 'g++' failed with exit status 1

ahartikainen commented 6 years ago

Hi, sorry,

I first read that your compiler was 4.7, but it is 4.4.7 which does not support c++11. So you should upgrade your gcc. Is there some special reason for that compiler version?

http://pystan.readthedocs.io/en/latest/whats_new.html

https://gcc.gnu.org/projects/cxx-status.html#cxx11

elena-zamfir commented 6 years ago

Thank you for your message. I've just checked this. In fact, the python version and the gcc version in the environment are different from the default ones outside the environment. (I don't understand why. I created the environment with conda create -n stan python=2.7 numpy cython)

Also, it seems that the gcc version that python is using is different from the one that I get with gcc --version in the command line. The error message was about g++ now, but there isn't any g++ version installed, it seems.

In the environment, I have GCC 7.2.0: (stan) elena@u236d:~$ python Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55) [GCC 7.2.0] on linux2 Type "help", "copyright", "credits" or "license" for more information.

(stan) elena@u236d:~$ gcc --version gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(stan) elena@u236d:~$ g++ --version The program 'g++' is currently not installed. To run 'g++' please ask your administrator to install the package 'g++'

ahartikainen commented 6 years ago

The GCC 7.2.0 is referring to the compiler toolset that was used to build python. It is not affecting your gcc usage.

The problem seems to be that you have GCC 5.4.0 on your system, but your anaconda is using GCC 4.4.7 which has ABI incompatibility with 5.4.0. Somewhere there is probably libstdc++ file that is linking to wrong compiler.

Can you install build-essential? Then your virtual environment should work.

sudo apt-get update
sudo apt-get install build-essential

For anaconda, can you update it or install latest version from anaconda.org? This probably will fix the problem with Anaconda environment.

conda update anaconda
elena-zamfir commented 6 years ago

Thank you! Now it works in the environment. I'll try to fix the Anaconda environment as well.

DKilkenny commented 6 years ago

You have no idea how much you've helped me. Thank you so much!

SunjunKim commented 6 years ago

On a Mac with Anaconda 3, I encountered the same problem and solved as like this:

------------ Error messages I encountered:

>>> import pystan >>> sm = pystan.StanModel(file='8schools.stan') INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_4337cb01f5c9774a0dd265dcc01c105e NOW. /Users/inornate/anaconda3/envs/stan/lib/python3.6/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /var/folders/3h/rvssdbf52fs97qcqqy15jrmc0000gn/T/tmp3zmptd1f/stanfit4anon_model_4337cb01f5c9774a0dd265dcc01c105e_5820254445497118413.pyx tree = Parsing.p_module(s, pxd, full_module_name)

Traceback (most recent call last): File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/model.py", line 350, in init build_extension.run() File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/Users/inornate/anaconda3/envs/stan/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1

s-blume commented 6 years ago

I seem to have a very similar problem. I've been using pystan on my Mac and everything has always been running smoothly -- until I upgraded pystan and Xcode (to Xcode 10). I'm not sure which of these upgrades has triggered the error, but I don't seem to be able to solve my problem. I'm using Anaconda, and have been trying all of the above, and even uninstalling and re-installing Anaconda entirely. I'm still getting the same error.

After going by the following steps:

conda create -n stan python=3.6 numpy cython
source activate stan
pip install pystan

And using this model code:

import pystan

schools_code = """
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
real eta[J];
}
transformed parameters {
real theta[J];
for (j in 1:J)
theta[j] = mu + tau * eta[j];
}
model {
eta ~ normal(0, 1);
y ~ normal(theta, sigma);
}
"""

schools_dat = {'J': 8,
'y': [28, 8, -3, 7, -1, 1, 18, 12],
'sigma': [15, 10, 16, 11, 9, 11, 10, 18]}

sm = pystan.StanModel(model_code=schools_code, verbose=True)

Here's the verbose output of the compiler:

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_3196c95ac936f62f173636d78c9ea8a9 NOW. INFO:pystan:OS: darwin, Python: 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)], Cython 0.29 Compiling /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_4533501486036397490.pyx because it changed. [1/1] Cythonizing /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_4533501486036397490.pyx /Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_4533501486036397490.pyx tree = Parsing.p_module(s, pxd, full_module_name) building 'stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_4533501486036397490' extension creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/var creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/var/folders creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/var/folders/zx creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/username/anaconda3/envs/stan/include -arch x86_64 -I/Users/username/anaconda3/envs/stan/include -arch x86_64 -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/src -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math/lib/eigen_3.3.3 -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math/lib/boost_1.66.0 -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math/lib/sundials_3.1.0/include -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/numpy/core/include -I/Users/username/anaconda3/envs/stan/include/python3.6m -c /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_4533501486036397490.cpp -o /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_4533501486036397490.o -O2 -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++11 warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found] /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmppoxz8qyv/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_4533501486036397490.cpp:675:10: fatal error: 'ios' file not found

include "ios"

     ^~~~~

1 warning and 1 error generated. Traceback (most recent call last): File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/username/mcmc/schools.py", line 29, in sm = pystan.StanModel(model_code=schools_code, verbose=True) File "/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/model.py", line 350, in init build_extension.run() File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1

The error is obviously coming from the #include "ios" I guess in one of the header files, but I'm at a loss on how to fix it. Any help would really be appreciated.

ahartikainen commented 6 years ago

Maybe this has something to do with the error

warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

Can you try installing gcc from conda

conda install gcc
s-blume commented 6 years ago

Hi! Thanks

I tried

conda install gcc

Now I'm getting this:

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_3196c95ac936f62f173636d78c9ea8a9 NOW. INFO:pystan:OS: darwin, Python: 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)], Cython 0.29 Compiling /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_9067146142311896432.pyx because it changed. [1/1] Cythonizing /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_9067146142311896432.pyx /Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_9067146142311896432.pyx tree = Parsing.p_module(s, pxd, full_module_name) building 'stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_9067146142311896432' extension creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/var creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/var/folders creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/var/folders/zx creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T creating /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/username/anaconda3/envs/stan/include -arch x86_64 -I/Users/username/anaconda3/envs/stan/include -arch x86_64 -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/src -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math/lib/eigen_3.3.3 -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math/lib/boost_1.66.0 -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/stan/lib/stan_math/lib/sundials_3.1.0/include -I/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/numpy/core/include -I/Users/username/anaconda3/envs/stan/include/python3.6m -c /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_9067146142311896432.cpp -o /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_9067146142311896432.o -O2 -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++11 cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default] In file included from /Users/username/anaconda3/envs/stan/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/include-fixed/syslimits.h:7:0, from /Users/username/anaconda3/envs/stan/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/include-fixed/limits.h:34, from /Users/username/anaconda3/envs/stan/include/python3.6m/Python.h:11, from /var/folders/zx/ts9l238547v5frxmn_qxk7wc0000gn/T/tmp0r5qv7_y/stanfit4anon_model_3196c95ac936f62f173636d78c9ea8a9_9067146142311896432.cpp:57: /Users/username/anaconda3/envs/stan/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/include-fixed/limits.h:168:61: fatal error: limits.h: No such file or directory

include_next / recurse down to the real one /

                                                         ^

compilation terminated. Traceback (most recent call last): File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "schools.py", line 29, in sm = pystan.StanModel(model_code=schools_code, verbose=True) File "/Users/username/anaconda3/envs/stan/lib/python3.6/site-packages/pystan/model.py", line 350, in init build_extension.run() File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/Users/username/anaconda3/envs/stan/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1

s-blume commented 6 years ago

Problem solved! Even though Xcode showed some version of Command Line Tools installed, it apparently still didn't work.

A simple

xcode-select --install

and hitting Install did the trick.

s-blume commented 6 years ago

Thanks at @ahartikainen for the help!

S-Black commented 5 years ago

Hi, I'm installying PyStan for the first time on a Windows machine and am getting a compilation error. I'm just running the test code from the website:

import pystan model_code = 'parameters {real y;} model {y ~ normal(0,1);}' model = pystan.StanModel(model_code=model_code) y = model.sampling().extract()['y'] y.mean() # with luck the result will be near 0

I have added the distutils.cfg file with the [build] compiler=mingw. I've also changed the cygwincompiler.py file to include the latest Visual Studio verion. In my case it's 1916 and I've got the vcruntime140.dll file in libs. It appeared as if doing those two things have made some improvement. However, I now get error "distutils.errors.CompileError: command 'C:\Program Files\mingw-w64\mingw64\bin\gcc.exe' failed with exit status 1"

My Python version is 3.7.3 and my gcc version is 8.1.0. I don't have anaconda.

My python output is this:

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_5944b02c79788fa0db5b3a93728ca2bf NOW. Traceback (most recent call last): File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\cygwinccompiler.py", line 181, in _compile extra_postargs) File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\spawn.py", line 38, in spawn _spawn_nt(cmd, search_path, dry_run=dry_run) File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\spawn.py", line 81, in _spawn_nt "command %r failed with exit status %d" % (cmd, rc)) distutils.errors.DistutilsExecError: command 'C:\Program Files\mingw-w64\mingw64\bin\gcc.exe' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\username\Documents\Python\test.py", line 9, in model = pystan.StanModel(model_code=model_code) File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pystan\model.py", line 349, in init build_extension.run() File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\build_ext.py", line 340, in run self.build_extensions() File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\build_ext.py", line 449, in build_extensions self._build_extensions_serial() File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial self.build_extension(ext) File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\build_ext.py", line 534, in build_extension depends=ext.depends) File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\distutils\cygwinccompiler.py", line 183, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'C:\Program Files\mingw-w64\mingw64\bin\gcc.exe' failed with exit status 1

Process returned 1 (0x1) execution time : 26.753 s Press any key to continue . . .

ahartikainen commented 5 years ago

I would first try with m2w64-toolchain and libpython

S-Black commented 5 years ago

Thanks @ahartikainen, I decided to install PyStan through Anaconda in the end to make my life easier. It worked fine following the instructions .

My main reason for trying to avoid anaconda was that I like to use the Atom editor and didn't want to learn Jupyter just now. I managed to get PyStan to work in Atom in the end after searching all over the place. I would like to write a post about it somewhere in case other people are trying to do the same thing. Where would be the best place for it?

ahartikainen commented 5 years ago

Great that it works!

Maybe in the docs?

Feel free to make a PR.

YuMiaoTHU commented 5 years ago

Hi, I have the same question! I have tried all method mentioned. I try to use fastXML not PyStan......but the error is same, so I want some help..... I tried many ways to solve the error....... 1: conda create -n py36 python=3.6 numpy cython source activate py36 run the code 2: conda install gcc 3: conda upgrade anaconda

I use anaconda, python=3.6, gcc=4.8.5, on a linux machine My python output is:

taskA/BoWcode/fastxml-master/fastxml/inferencer.pyx:102:11: Call with wrong number of arguments (expected 3, got 2) /home/ymm/.pyxbld/temp.linux-x86_64-3.6/pyrex/fastxml/inferencer.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.

error Do not use this file, it is the result of a failed Cython compilation.

^ Traceback (most recent call last): File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyximport.py", line 215, in load_module inplace=build_inplace, language_level=language_level) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyximport.py", line 191, in build_module reload_support=pyxargs.reload_support) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyxbuild.py", line 102, in pyx_to_dll dist.run_commands() File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 194, in build_extensions self.build_extension(ext) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/ymm/taskA/BoWcode/fastxml-master/abstract_fastxml.py", line 1, in from fastxml import trainer, inferencer File "/home/ymm/taskA/BoWcode/fastxml-master/fastxml/init.py", line 1, in from .fastxml import Inferencer File "/home/ymm/taskA/BoWcode/fastxml-master/fastxml/fastxml.py", line 11, in from .inferencer import IForest, LeafComputer, Blender, IForestBlender File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyximport.py", line 462, in load_module language_level=self.language_level) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyximport.py", line 231, in load_module raise exc.with_traceback(tb) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyximport.py", line 215, in load_module inplace=build_inplace, language_level=language_level) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyximport.py", line 191, in build_module reload_support=pyxargs.reload_support) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/pyximport/pyxbuild.py", line 102, in pyx_to_dll dist.run_commands() File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 194, in build_extensions self.build_extension(ext) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/home/ymm/anaconda3/envs/ymm_abstract/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) ImportError: Building module fastxml.inferencer failed: ["distutils.errors.CompileError: command 'gcc' failed with exit status 1\n"]

ahartikainen commented 5 years ago

Sorry, I have no idea what is going on with fastxml.

See our updated instructions for C++ toolchain https://github.com/stan-dev/pystan/blob/develop/doc/installation_beginner.rst

Also you could try to recreate cython files.

YuMiaoTHU commented 5 years ago

Tanks for your reply!!! I have fix the bug!!!

ahartikainen commented 5 years ago

Closing due to inactivity. Can be reopened if needed.

afsangujarati93 commented 5 years ago

Maybe this has something to do with the error

warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

Can you try installing gcc from conda

conda install gcc

This worked for me. However, when I tried this it gave me the following error Operation not permitted That can be fixed by deleting the *.app files in ~/anaconda3/ and ~/anaconda3/bin/ folders Referred from: https://github.com/conda/conda/issues/8440#issuecomment-481167572