質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.35%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

1回答

618閲覧

Windows10環境でprophetを実行したい

chem_search

総合スコア30

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2024/08/08 02:00

実現したいこと

ローカル環境のjupyter notebookでprophetのライブラリを用いた解析を行いたいと考えています。

発生している問題・分からないこと

prophetをインストールし、動かそうとしたのですが、
「AttributeError: 'Prophet' object has no attribute 'stan_backend'」
とエラーが出ました。
調べると、pystanが動く環境である必要があるとのことだったので、
pystanのインストールを行ったのですが、これも上手くコンパイルできずに困っています。
どのように対処すればうまく動くようになるかご教授頂きたいです。

エラーメッセージ

error

1DistutilsExecError Traceback (most recent call last) 2D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\cygwinccompiler.py in _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) 3 144 self.spawn( 4--> 145 self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs 5 146 ) 6 7D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\ccompiler.py in spawn(self, cmd, **kwargs) 8 1006 def spawn(self, cmd, **kwargs): 9-> 1007 spawn(cmd, dry_run=self.dry_run, **kwargs) 10 1008 11 12D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\spawn.py in spawn(cmd, search_path, verbose, dry_run, env) 13 70 raise DistutilsExecError( 14---> 71 "command {!r} failed with exit code {}".format(cmd, exitcode) 15 72 ) 16 17DistutilsExecError: command 'C:\\Users\\○○○\\anaconda3\\Library\\mingw-w64\\bin\\gcc.exe' failed with exit code 1 18 19During handling of the above exception, another exception occurred: 20 21CompileError Traceback (most recent call last) 22~\AppData\Local\Temp\ipykernel_13756\1613198025.py in <module> 23 1 from pystan import StanModel 24 2 25----> 3 model = StanModel(model_code="parameters {real y;} model {y ~ normal(0,1);}") 26 4 print(model.sampling()["y"].mean()) 27 28D:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan\model.py in __init__(self, file, charset, model_name, model_code, stanc_ret, include_paths, boost_lib, eigen_lib, verbose, obfuscate_model_name, extra_compile_args, allow_undefined, include_dirs, includes) 29 376 30 377 try: 31--> 378 build_extension.run() 32 379 finally: 33 380 if redirect_stderr: 34 35D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in run(self) 36 344 37 345 # Now actually compile and link everything. 38--> 346 self.build_extensions() 39 347 40 348 def check_extensions_list(self, extensions): # noqa: C901 41 42D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in build_extensions(self) 43 466 self._build_extensions_parallel() 44 467 else: 45--> 468 self._build_extensions_serial() 46 469 47 470 def _build_extensions_parallel(self): 48 49D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in _build_extensions_serial(self) 50 492 for ext in self.extensions: 51 493 with self._filter_build_errors(ext): 52--> 494 self.build_extension(ext) 53 495 54 496 @contextlib.contextmanager 55 56D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in build_extension(self, ext) 57 554 debug=self.debug, 58 555 extra_postargs=extra_args, 59--> 556 depends=ext.depends, 60 557 ) 61 558 62 63D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\ccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends) 64 597 except KeyError: 65 598 continue 66--> 599 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) 67 600 68 601 # Return *all* object filenames, not just the ones we just built. 69 70D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\cygwinccompiler.py in _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) 71 146 ) 72 147 except DistutilsExecError as msg: 73--> 148 raise CompileError(msg) 74 149 75 150 def link( 76 77CompileError: command 'C:\\Users\\○○○\\anaconda3\\Library\\mingw-w64\\bin\\gcc.exe' failed with exit code 1

該当のソースコード

Python

1from pystan import StanModel 2 3model = StanModel(model_code="parameters {real y;} model {y ~ normal(0,1);}") 4print(model.sampling()["y"].mean())

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

https://pystan2.readthedocs.io/en/latest/windows.html
https://indonegiyaland.hatenablog.com/entry/2022/03/31/162245
上記のページを参考に設定しました。

補足

仮想環境で実施しており、インストールしているライブラリは以下の通りです。
(関係あると思われるもののみ抜粋しています)
Name Version Build Channel
cython 0.29.32 py37hf2a7229_0 conda-forge
ephem 4.1.2 py37h2bbff1b_0
holidays 0.18 py37haa95532_0
libpython 2.1 py37_0
m2w64-binutils 2.25.1 5
m2w64-bzip2 1.0.6 6
m2w64-crt-git 5.0.0.4636.2595836 2
m2w64-gcc 5.3.0 6
m2w64-gcc-ada 5.3.0 6
m2w64-gcc-fortran 5.3.0 6
m2w64-gcc-libgfortran 5.3.0 6
m2w64-gcc-libs 5.3.0 7
m2w64-gcc-libs-core 5.3.0 7
m2w64-gcc-objc 5.3.0 6
m2w64-gmp 6.1.0 2
m2w64-headers-git 5.0.0.4636.c0ad18a 2
m2w64-isl 0.16.1 2
m2w64-libiconv 1.14 6
m2w64-libmangle-git 5.0.0.4509.2e5a9a2 2
m2w64-libwinpthread-git 5.0.0.4634.697f757 2
m2w64-make 4.1.2351.a80a8b8 2
m2w64-mpc 1.0.3 3
m2w64-mpfr 3.1.4 4
m2w64-pkg-config 0.29.1 2
m2w64-toolchain 5.3.0 7 msys2
m2w64-tools-git 5.0.0.4592.90b8472 2
m2w64-windows-default-manifest 6.4 3
m2w64-winpthreads-git 5.0.0.4634.697f757 2
m2w64-zlib 1.2.8 10
mkl 2020.2 256
prophet 1.0.1 py37haa95532_0
pystan 2.19.1.1 py37hac22706_0
python 3.7.16 h6244533_0
setuptools 65.6.3 py37haa95532_0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

quickquip

2024/08/08 03:18

該当のソースコード に書いてあるコードの実行結果が エラーメッセージ に書いてあるものですか? 上の方に省略がありますか?
chem_search

2024/08/08 03:37

ご回答ありがとうございます。 該当のソースコードを実行した結果出力されたエラーメッセージが上記の通りです。省略はしていません。 また、pystanのインストールにおいては、仮想環境作成後、 conda install cython,numpy conda install pystan==2.19.1.1 conda install libpython m2w64-toolchain -c msys2 とインストールし、 「試したこと・調べたこと」のリンク先にあるdistutils.cfgファイルは問題無くできていることを確認しました。 また、 https://guppi524.hatenablog.jp/entry/2022/12/24/191910 こちらのページには import distutils print(distutils.__file__) で出力されるパスにdistutils.cfgをコピーする必要があると 記載されていたので、そちらも試しました。 その後のコード実行結果が記載したものになります。
quickquip

2024/08/08 04:19

model.py を読んでみると model = StanModel(model_code="parameters {real y;} model {y ~ normal(0,1);}", verbose=True) とか verbose=2 とかすることでビルドのログが増えそうでした 見てみてはどうでしょうか
chem_search

2024/08/08 04:38

ありがとうございます。 試してみましたが、以下の通りでした。エラー部分は変わらないように思います。 INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_5944b02c79788fa0db5b3a93728ca2bf NOW. INFO:pystan:OS: win32, Python: 3.7.16 (default, Jan 17 2023, 16:06:28) [MSC v.1916 64 bit (AMD64)], Cython 0.29.32 Compiling C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_2102178565924967345.pyx because it changed. [1/1] Cythonizing C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_2102178565924967345.pyx INFO:root:building 'stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_2102178565924967345' extension INFO:root:creating C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\users INFO:root:creating C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\users\○○○ INFO:root:creating C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\users\○○○\appdata INFO:root:creating C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\users\○○○\appdata\local INFO:root:creating C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\users\○○○\appdata\local\temp INFO:root:creating C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\users\○○○\appdata\local\temp\pystan_yi8rt05r INFO:root:gcc -mdll -O -Wall -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -IC:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r -ID:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan -ID:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan\stan\src -ID:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan\stan\lib\stan_math -ID:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan\stan\lib\stan_math\lib\eigen_3.3.3 -ID:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan\stan\lib\stan_math\lib\boost_1.69.0 -ID:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan\stan\lib\stan_math\lib\sundials_4.1.0\include -ID:\Anaconda_envs\envs\prophet_env\lib\site-packages\numpy\core\include -ID:\Anaconda_envs\envs\prophet_env\include -ID:\Anaconda_envs\envs\prophet_env\Include -c C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_2102178565924967345.cpp -o C:\Users\○○○\AppData\Local\Temp\pystan_yi8rt05r\users\○○○\appdata\local\temp\pystan_yi8rt05r\stanfit4anon_model_5944b02c79788fa0db5b3a93728ca2bf_2102178565924967345.o -O2 -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++1y -D_hypot=hypot -pthread -fexceptions --------------------------------------------------------------------------- DistutilsExecError Traceback (most recent call last) D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\cygwinccompiler.py in _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) 144 self.spawn( --> 145 self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs 146 ) D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\ccompiler.py in spawn(self, cmd, **kwargs) 1006 def spawn(self, cmd, **kwargs): -> 1007 spawn(cmd, dry_run=self.dry_run, **kwargs) 1008 D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\spawn.py in spawn(cmd, search_path, verbose, dry_run, env) 70 raise DistutilsExecError( ---> 71 "command {!r} failed with exit code {}".format(cmd, exitcode) 72 ) DistutilsExecError: command 'C:\\Users\\○○○\\anaconda3\\Library\\mingw-w64\\bin\\gcc.exe' failed with exit code 1 During handling of the above exception, another exception occurred: CompileError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_8112\1436560234.py in <module> 1 from pystan import StanModel 2 ----> 3 model = StanModel(model_code="parameters {real y;} model {y ~ normal(0,1);}", verbose=True) 4 print(model.sampling()["y"].mean()) D:\Anaconda_envs\envs\prophet_env\lib\site-packages\pystan\model.py in __init__(self, file, charset, model_name, model_code, stanc_ret, include_paths, boost_lib, eigen_lib, verbose, obfuscate_model_name, extra_compile_args, allow_undefined, include_dirs, includes) 376 377 try: --> 378 build_extension.run() 379 finally: 380 if redirect_stderr: D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in run(self) 344 345 # Now actually compile and link everything. --> 346 self.build_extensions() 347 348 def check_extensions_list(self, extensions): # noqa: C901 D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in build_extensions(self) 466 self._build_extensions_parallel() 467 else: --> 468 self._build_extensions_serial() 469 470 def _build_extensions_parallel(self): D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in _build_extensions_serial(self) 492 for ext in self.extensions: 493 with self._filter_build_errors(ext): --> 494 self.build_extension(ext) 495 496 @contextlib.contextmanager D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\command\build_ext.py in build_extension(self, ext) 554 debug=self.debug, 555 extra_postargs=extra_args, --> 556 depends=ext.depends, 557 ) 558 D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\ccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends) 597 except KeyError: 598 continue --> 599 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) 600 601 # Return *all* object filenames, not just the ones we just built. D:\Anaconda_envs\envs\prophet_env\lib\site-packages\setuptools\_distutils\cygwinccompiler.py in _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) 146 ) 147 except DistutilsExecError as msg: --> 148 raise CompileError(msg) 149 150 def link( CompileError: command 'C:\\Users\\○○○\\anaconda3\\Library\\mingw-w64\\bin\\gcc.exe' failed with exit code 1
meg_

2024/08/08 11:18 編集

> prophetをインストールし、動かそうとしたのですが、 > 「AttributeError: 'Prophet' object has no attribute 'stan_backend'」 > とエラーが出ました。 エラーが発生したコードはどのようなものでしょうか? pipで上手く行かない場合はcondaでインストールすると上手く行く場合もあるようです。
meg_

2024/08/09 11:39 編集

Windows11、Python 3.11.4、prophet 1.1.5の組み合わせではドキュメントに沿って行ったpipでのインストールおよびQuickStartのm.fit(df)までのコード実行ではエラーは発生しませんでした。 Pythonは3.7でないといけないのでしょうか?そうでないなら組み合わせを変えてみてはどうでしょうか?
chem_search

2024/08/12 22:08

アドバイスありがとうございます。 ①仮想環境の作製(python=3.11.9) ②pipでのライブラリのインストール(prophet=1.1.5) を行って実行したところ、新たなエラー (AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.) がでたため、numpyをimportした後、 np.float_ = np.float64 を実行してからprophetをimportすることで、エラー無く実行することができました。 pythonやライブラリ間の依存関係が問題だったということでしょうか・・・・・・。
guest

回答1

0

3系の実行環境はこうなってます

https://pystan.readthedocs.io/en/latest/installation.html

Linux or macOS

https://pystan.readthedocs.io/en/latest/faq.html#is-windows-supported

Is Windows supported?

If WSL2 works for you, then the answer is “yes,” otherwise the answer is “no.”


質問で

pystanのインストールを行ったのですが

とだけ書いてあって「実際なにをしたのか?」か書かれていないので推測となりますが、これは3系をインストールしようとしてしまっていませんか?

投稿2024/08/08 02:51

編集2024/08/08 02:55
quickquip

総合スコア11235

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

quickquip

2024/08/08 03:15

すみません。とりあえずこの回答は無視してもらってよいです
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.35%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問