Hard time importing pymc3 - compilation error?

Hello there,
I"ve been having hard time installing and importing pymc3 today, as I started following the book Bayesian Methods for Hackers (and there’s also the Bayesian Analysis with Python on my shelf, so hopefully I will find a solution to this). Of course, at first I installed via pip install pymc3, which as I later discovered at the installation tutorial site is not the way to go. So I got rid of the old python distribution on my laptop and installed conda. Then I followed the said tutorial. After I started the following cell in Jupyter Notebook:

import pymc3 as pm
import theano.tensor as tt

with pm.Model() as model:
alpha = 1.0/count_data.mean() #mean value of the count
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)

I got the following:

You can find the C code in this temporary file: C:\Users\hartd\AppData\Local\Temp\theano_compilation_error_ink1egkr

Exception Traceback (most recent call last)
in
4 with pm.Model() as model:
5 alpha = 1.0/count_data.mean() #mean value of the count
----> 6 lambda_1 = pm.Exponential(“lambda_1”, alpha)
7 lambda_2 = pm.Exponential(“lambda_2”, alpha)
8

c:\users\hartd\miniconda3\lib\site-packages\pymc3\distributions\distribution.py in new(cls, name, *args, **kwargs)
119 dist = cls.dist(*args, **kwargs, shape=shape)
120 else:
→ 121 dist = cls.dist(*args, **kwargs)
122 return model.Var(name, dist, data, total_size, dims=dims)
123

c:\users\hartd\miniconda3\lib\site-packages\pymc3\distributions\distribution.py in dist(cls, *args, **kwargs)
128 def dist(cls, *args, **kwargs):
129 dist = object.new(cls)
→ 130 dist.init(*args, **kwargs)
131 return dist
132

c:\users\hartd\miniconda3\lib\site-packages\pymc3\distributions\continuous.py in init(self, lam, *args, **kwargs)
1485 super().init(*args, **kwargs)
1486 self.lam = lam = tt.as_tensor_variable(floatX(lam))
→ 1487 self.mean = 1.0 / self.lam
1488 self.median = self.mean * tt.log(2)
1489 self.mode = tt.zeros_like(self.lam)

c:\users\hartd\miniconda3\lib\site-packages\theano\tensor\var.py in rtruediv(self, other)
174
175 def rtruediv(self, other):
→ 176 return theano.tensor.basic.true_div(other, self)
177
178 def rfloordiv(self, other):

c:\users\hartd\miniconda3\lib\site-packages\theano\graph\op.py in call(self, *inputs, **kwargs)
251
252 if config.compute_test_value != “off”:
→ 253 compute_test_value(node)
254
255 if self.default_output is not None:

c:\users\hartd\miniconda3\lib\site-packages\theano\graph\op.py in compute_test_value(node)
124
125 # Create a thunk that performs the computation
→ 126 thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
127 thunk.inputs = [storage_map[v] for v in node.inputs]
128 thunk.outputs = [storage_map[v] for v in node.outputs]

c:\users\hartd\miniconda3\lib\site-packages\theano\graph\op.py in make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
632 )
633 try:
→ 634 return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
635 except (NotImplementedError, MethodNotDefined):
636 # We requested the c code, so don’t catch the error.

c:\users\hartd\miniconda3\lib\site-packages\theano\graph\op.py in make_c_thunk(self, node, storage_map, compute_map, no_recycling)
598 print(f"Disabling C code for {self} due to unsupported float16")
599 raise NotImplementedError(“float16”)
→ 600 outputs = cl.make_thunk(
601 input_storage=node_input_storage, output_storage=node_output_storage
602 )

c:\users\hartd\miniconda3\lib\site-packages\theano\link\c\basic.py in make_thunk(self, input_storage, output_storage, storage_map)
1201 “”"
1202 init_tasks, tasks = self.get_init_tasks()
→ 1203 cthunk, module, in_storage, out_storage, error_storage = self.compile(
1204 input_storage, output_storage, storage_map
1205 )

c:\users\hartd\miniconda3\lib\site-packages\theano\link\c\basic.py in compile(self, input_storage, output_storage, storage_map)
1136 input_storage = tuple(input_storage)
1137 output_storage = tuple(output_storage)
→ 1138 thunk, module = self.cthunk_factory(
1139 error_storage,
1140 input_storage,

c:\users\hartd\miniconda3\lib\site-packages\theano\link\c\basic.py in cthunk_factory(self, error_storage, in_storage, out_storage, storage_map)
1632 for node in self.node_order:
1633 node.op.prepare_node(node, storage_map, None, “c”)
→ 1634 module = get_module_cache().module_from_key(key=key, lnk=self)
1635
1636 vars = self.inputs + self.outputs + self.orphans

c:\users\hartd\miniconda3\lib\site-packages\theano\link\c\cmodule.py in module_from_key(self, key, lnk)
1189 try:
1190 location = dlimport_workdir(self.dirname)
→ 1191 module = lnk.compile_cmodule(location)
1192 name = module.file
1193 assert name.startswith(location)

c:\users\hartd\miniconda3\lib\site-packages\theano\link\c\basic.py in compile_cmodule(self, location)
1541 try:
1542 _logger.debug(f"LOCATION {location}")
→ 1543 module = c_compiler.compile_str(
1544 module_name=mod.code_hash,
1545 src_code=src_code,

c:\users\hartd\miniconda3\lib\site-packages\theano\link\c\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
2544 # difficult to read.
2545 compile_stderr = compile_stderr.replace("\n", ". “)
→ 2546 raise Exception(
2547 f"Compilation failed (return status={status}): {compile_stderr}”
2548 )

Exception: ("Compilation failed (return status=1): C:\Users\hartd\AppData\Local\Temp\ccyIHuKH.o: In function run':\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:99: undefined reference to __imp__Py_NoneStruct’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:124: undefined reference to __imp_PyExc_ValueError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:130: undefined reference to __imp_PyExc_RuntimeError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:158: undefined reference to __imp_PyExc_NotImplementedError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:195: undefined reference to __imp__Py_NoneStruct’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:210: undefined reference to __imp_PyExc_ValueError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:479: undefined reference to __imp_PyExc_NotImplementedError’\r. C:\Users\hartd\AppData\Local\Temp\ccyIHuKH.o: In function _Py_INCREF':\r. c:/users/hartd/miniconda3/include/object.h:459: undefined reference to __imp__Py_NoneStruct’\r. C:\Users\hartd\AppData\Local\Temp\ccyIHuKH.o: In function run':\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:485: undefined reference to __imp_PyExc_RuntimeError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:244: undefined reference to __imp_PyExc_NotImplementedError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:265: undefined reference to __imp_PyExc_RuntimeError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:173: undefined reference to __imp_PyExc_TypeError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:179: undefined reference to __imp_PyExc_RuntimeError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:515: undefined reference to __imp__Py_NoneStruct'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:514: undefined reference to __imp__Py_NoneStruct’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:516: undefined reference to __imp__Py_NoneStruct'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:259: undefined reference to __imp_PyExc_TypeError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:279: undefined reference to __imp__Py_NoneStruct'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:294: undefined reference to __imp_PyExc_ValueError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:328: undefined reference to __imp_PyExc_NotImplementedError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:349: undefined reference to __imp_PyExc_RuntimeError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:216: undefined reference to __imp_PyExc_RuntimeError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:343: undefined reference to __imp_PyExc_TypeError’\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:300: undefined reference to __imp_PyExc_RuntimeError'\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:397: undefined reference to __imp_PyExc_RuntimeError’\r. C:\Users\hartd\AppData\Local\Temp\ccyIHuKH.o: In function instantiate':\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:550: undefined reference to __imp_PyExc_TypeError’\r. C:\Users\hartd\AppData\Local\Temp\ccyIHuKH.o: In function _import_array':\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1480: undefined reference to __imp_PyCapsule_Type’\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1481: undefined reference to __imp_PyExc_RuntimeError'\r. C:\\Users\\hartd\\AppData\\Local\\Temp\\ccyIHuKH.o: In function PyInit_m31975b6dadb59d49af3f2b36405378825884299512ee0ed9081be33fa591d30d’:\r. C:/Users/hartd/AppData/Local/Theano/compiledir_Windows-10-10.0.18362-SP0-Intel64_Family_6_Model_126_Stepping_5_GenuineIntel-3.8.5-64/tmp3ufqyh3q/mod.cpp:583: undefined reference to __imp_PyExc_ImportError'\r. C:\\Users\\hartd\\AppData\\Local\\Temp\\ccyIHuKH.o: In function _import_array’:\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1512: undefined reference to __imp_PyExc_RuntimeError'\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1496: undefined reference to __imp_PyExc_RuntimeError’\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1502: undefined reference to __imp_PyExc_RuntimeError'\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1524: undefined reference to __imp_PyExc_RuntimeError’\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1476: undefined reference to __imp_PyExc_AttributeError'\r. c:/users/hartd/miniconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1488: undefined reference to __imp_PyExc_RuntimeError’\r. collect2.exe: error: ld returned 1 exit status\r. ", ‘FunctionGraph(Elemwise{true_div,no_inplace}(TensorConstant{1.0}, TensorConstant{0.05065023956194388}))’)

I followed the installation guide, activated the relevant conda env and after finally getting rid of all the errors that appeared previously, this monster came up. Any idea what’s wrong, please?

What versions of pymc3 and theano are you using? Can you provide the installation commands you used?

sure, I followed this guide

and used exactly the same commands via conda prompt, i.e.

conda create -n mypm3env python=3.8 mkl-service libpython m2w64-toolchain scipy matplotlib pandas

and then within the env

conda install -c conda-forge pymc3

The version of pymc3 is 3.11.1 and theano-pymc 1.1.2

Is it possible that the jupyter notebook is not actually accessing your conda environment? The fact that the paths to your theano directory in your error message don’t appear to be referencing a conda environment seems suspect. As far as I’m aware there are additional steps you need to do to configure your jupyter notebook kernal to use a conda environment. See:

Yeah that was it. So dumb. I hadn’t really used Conda before as i prefer to keep my environments as simple as possible, so this is really helpful. Thanks! Have a nice day dear sir.

1 Like