本文介绍了Pymc3 theano 导入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直无法确定 Pymc3 无法正确运行 Theano 的问题.我也一直无法在网上其他任何地方找到满意的答案.我正在使用 Anaconda 和 Python 3.6 在 Mac OSX Mojave 中工作.我正在尝试在黑客的概率编程和贝叶斯方法"中的 Jupyter Notebook 上运行代码.

I have been unable to identify the issue with Pymc3's inability to correctly run Theano. I have also been unable to find a satisfactory answer anywhere else online. I am working in Mac OSX Mojave using Anaconda and Python 3.6. I am trying to run the code on a Jupyter Notebook from "Probabilistic Programming and Bayesian Methods for Hackers".

https://nbviewer.jupyter.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC3.ipynb

第一次尝试使用 Pymc3 时代码中断:

Code breaks with the first attempt to utilize Pymc3:

import pymc3 as pm
import theano.tensor as tt

with pm.Model() as model:
    alpha = 1.0/count_data.mean()  # Recall count_data is the
                                   # variable that holds our txt counts
    lambda_1 = pm.Exponential("lambda_1", alpha)
    lambda_2 = pm.Exponential("lambda_2", alpha)

    tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data - 1)

错误代码如下.提前致谢.

Error code follows, below. Thanks in advance.

ImportError                               Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/theano/gof/lazylinker_c.py in <module>
     80                     version,
---> 81                     actual_version, force_compile, _need_reload))
     82 except ImportError:

ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/theano/gof/lazylinker_c.py in <module>
    104                         version,
--> 105                         actual_version, force_compile, _need_reload))
    106         except ImportError:

ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/theano/gof/vm.py in <module>
    673         raise theano.gof.cmodule.MissingGXX('lazylinker will not be imported if theano.config.cxx is not set.')
--> 674     from . import lazylinker_c
    675

/anaconda3/lib/python3.6/site-packages/theano/gof/lazylinker_c.py in <module>
    139             cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
--> 140                                              preargs=args)
    141             # Save version into the __init__.py file.

/anaconda3/lib/python3.6/site-packages/theano/gof/cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2398             raise Exception('Compilation failed (return status=%s): %s' %
-> 2399                             (status, compile_stderr.replace('\n', '. ')))
   2400         elif config.cmodule.compilation_warning and compile_stderr:

Exception: Compilation failed (return status=1): In file included from /Users/kthln/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.6.9-64/lazylinker_ext/mod.cpp:1:. In file included from /anaconda3/include/python3.6m/Python.h:25:. /anaconda3/bin/../include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found. #include_next <stdio.h>.               ^~~~~~~~~. 1 error generated..

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-48-f2e1580aa39f> in <module>
      1 import pymc3 as pm
----> 2 import theano.tensor as tt
      3
      4
      5 with pm.Model() as model:

/anaconda3/lib/python3.6/site-packages/theano/__init__.py in <module>
    108     object2, utils)
    109
--> 110 from theano.compile import (
    111     SymbolicInput, In,
    112     SymbolicOutput, Out,

/anaconda3/lib/python3.6/site-packages/theano/compile/__init__.py in <module>
     10 from theano.compile.function_module import *
     11
---> 12 from theano.compile.mode import *
     13
     14 from theano.compile.io import *

/anaconda3/lib/python3.6/site-packages/theano/compile/mode.py in <module>
      9 import theano
     10 from theano import gof
---> 11 import theano.gof.vm
     12 from theano import config
     13 from six import string_types

/anaconda3/lib/python3.6/site-packages/theano/gof/vm.py in <module>
    681 except ImportError:
    682     pass
--> 683 except (OSError, theano.gof.cmodule.MissingGXX) as e:
    684     # OSError happens when g++ is not installed.  In that case, we
    685     # already changed the default linker to something else then CVM.

AttributeError: module 'theano' has no attribute 'gof'

推荐答案

无视.我注意到更新时我正在运行 Python 3.7.使用 Python 3.6 设置一个单独的 conda 环境,它工作正常.

Disregard. I noticed with an update I was running Python 3.7. Set up a separate conda env with Python 3.6 and it works fine.

这篇关于Pymc3 theano 导入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 09:42