vethno
vethno

Reputation: 141

Pymc3 theano import failure

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

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'

Upvotes: 2

Views: 1782

Answers (1)

vethno
vethno

Reputation: 141

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.

Upvotes: 1

Related Questions