Errors in importing pymc3

I just downloaded pymc3 and tried the linear regression example (example1) for a testdrive.
I ran into a few errors and exceptions that are related to lazylinker. Below are the full error messages. Any insight would be appreciated

ImportError                               Traceback (most recent call last)
~\Anaconda3\lib\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\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)
<ipython-input-3-07cd9aefb74b> in <module>()
----> 1 import pymc3 as pm
      2 print('Running on PyMC3 v{}'.format(pm.__version__))

~\Anaconda3\lib\site-packages\pymc3\__init__.py in <module>()
      3 
      4 from .blocking import *
----> 5 from .distributions import *
      6 from .external import *
      7 from .glm import *

~\Anaconda3\lib\site-packages\pymc3\distributions\__init__.py in <module>()
----> 1 from . import timeseries
      2 from . import transforms
      3 
      4 from .continuous import Uniform
      5 from .continuous import Flat

~\Anaconda3\lib\site-packages\pymc3\distributions\timeseries.py in <module>()
----> 1 import theano.tensor as tt
      2 from theano import scan
      3 
      4 from pymc3.util import get_variable_name
      5 from .continuous import get_tau_sd, Normal, Flat

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

~\Anaconda3\lib\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\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\site-packages\theano\gof\vm.py in <module>()
    672     if not theano.config.cxx:
    673         raise theano.gof.cmodule.MissingGXX('lazylinker will not be imported if theano.config.cxx is not set.')
--> 674     from . import lazylinker_c
    675 
    676     class CVM(lazylinker_c.CLazyLinker, VM):

~\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
    138             args = cmodule.GCC_compiler.compile_args()
    139             cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
--> 140                                              preargs=args)
    141             # Save version into the __init__.py file.
    142             init_py = os.path.join(loc, '__init__.py')

~\Anaconda3\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2386             # difficult to read.
   2387             raise Exception('Compilation failed (return status=%s): %s' %
-> 2388                             (status, compile_stderr.replace('\n', '. ')))
   2389         elif config.cmodule.compilation_warning and compile_stderr:
   2390             # Print errors just below the command line.

. collect2.exe: error: ld returned 1 exit statusdir_Windows-10-10.0.17134-SP0-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.5-64/lazylinker_ext/mod.cpp:976: undefined reference to `__imp__Py_TrueStruct'Error'e undefined references to `__imp__Py_NoneStruct' followow

Can you try import theano alone? Seems theano is not installed properly.

Thank you for the suggestion. I did reinstall theano and ran again. This time, I had different errors given below. I am wondering if it has something to do with the fact that I have installed python 3.6? (I read from Theano site that it supports Python version up to 3.5). Any help will be appreciated.

import pymc3 as pm
print(‘Running on PyMC3 v{}’.format(pm.version))


KeyError Traceback (most recent call last)
~\Anaconda3\lib\configparser.py in _unify_values(self, section, vars)
1137 try:
-> 1138 sectiondict = self._sections[section]
1139 except KeyError:

KeyError: ‘blas’

During handling of the above exception, another exception occurred:

NoSectionError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\theano\configparser.py in fetch_val_for_key(key, delete_key)
167 try:
–> 168 return theano_cfg.get(section, option)
169 except ConfigParser.InterpolationError:

~\Anaconda3\lib\configparser.py in get(self, section, option, raw, vars, fallback)
780 try:
–> 781 d = self._unify_values(section, vars)
782 except NoSectionError:

~\Anaconda3\lib\configparser.py in _unify_values(self, section, vars)
1140 if section != self.default_section:
-> 1141 raise NoSectionError(section)
1142 # Update with the entry specific variables

NoSectionError: No section: ‘blas’

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\theano\configparser.py in get(self, cls, type_, delete_key)
327 val_str = fetch_val_for_key(self.fullname,
–> 328 delete_key=delete_key)
329 self.is_default = False

~\Anaconda3\lib\site-packages\theano\configparser.py in fetch_val_for_key(key, delete_key)
171 except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
–> 172 raise KeyError(key)
173

KeyError: ‘blas.ldflags’

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)
in ()
----> 1 import pymc3 as pm
2 print(‘Running on PyMC3 v{}’.format(pm.version))

~\Anaconda3\lib\site-packages\pymc3_init_.py in ()
3
4 from .blocking import *
----> 5 from .distributions import *
6 from .external import *
7 from .glm import *

~\Anaconda3\lib\site-packages\pymc3\distributions_init_.py in ()
----> 1 from . import timeseries
2 from . import transforms
3
4 from .continuous import Uniform
5 from .continuous import Flat

~\Anaconda3\lib\site-packages\pymc3\distributions\timeseries.py in ()
----> 1 import theano.tensor as tt
2 from theano import scan
3
4 from pymc3.util import get_variable_name
5 from .continuous import get_tau_sd, Normal, Flat

~\Anaconda3\lib\site-packages\theano_init_.py in ()
122 from theano.printing import pprint, pp
123
–> 124 from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
125 scan_checkpoints)
126

~\Anaconda3\lib\site-packages\theano\scan_module_init_.py in ()
39 contact = “Razvan Pascanu r.pascanu@gmail
40
—> 41 from theano.scan_module import scan_opt
42 from theano.scan_module.scan import scan
43 from theano.scan_module.scan_checkpoints import scan_checkpoints

~\Anaconda3\lib\site-packages\theano\scan_module\scan_opt.py in ()
58
59 import theano
—> 60 from theano import tensor, scalar
61 from theano.tensor import opt, get_scalar_constant_value, Alloc, AllocEmpty
62 from theano import gof

~\Anaconda3\lib\site-packages\theano\tensor_init_.py in ()
15 from theano.tensor import opt
16 from theano.tensor import opt_uncanonicalize
—> 17 from theano.tensor import blas
18 from theano.tensor import blas_scipy
19 from theano.tensor import blas_c

~\Anaconda3\lib\site-packages\theano\tensor\blas.py in ()
153 from theano.scalar import bool as bool_t
154 from theano.tensor import basic as T
–> 155 from theano.tensor.blas_headers import blas_header_text
156 from theano.tensor.blas_headers import blas_header_version
157 from theano.tensor.opt import in2out, local_dimshuffle_lift

~\Anaconda3\lib\site-packages\theano\tensor\blas_headers.py in ()
985
986
–> 987 if not config.blas.ldflags:
988 _logger.warning(‘Using NumPy C-API based implementation for BLAS functions.’)
989

~\Anaconda3\lib\site-packages\theano\configparser.py in get(self, cls, type_, delete_key)
330 except KeyError:
331 if callable(self.default):
–> 332 val_str = self.default()
333 else:
334 val_str = self.default

~\Anaconda3\lib\site-packages\theano\configdefaults.py in default_blas_ldflags()
1428 if res:
1429 if ‘mkl’ in res:
-> 1430 check_mkl_openmp()
1431 return res
1432

~\Anaconda3\lib\site-packages\theano\configdefaults.py in check_mkl_openmp()
1250 import mkl
1251 if ‘2018’ in mkl.get_version_string():
-> 1252 raise RuntimeError(‘To use MKL 2018 with Theano you MUST set “MKL_THREADING_LAYER=GNU” in your environement.’)
1253 except ImportError:
1254 raise RuntimeError("""

RuntimeError: To use MKL 2018 with Theano you MUST set “MKL_THREADING_LAYER=GNU” in your environement.

Try the solution in: https://askubuntu.com/questions/974540/how-to-set-mkl-threading-layer-gnu-as-an-environment-variable-for-a-python-scr

This error will be fix in the next release of theano.

Are you under Windows? Linux? Mac?

I encountered a similar problem myself. In my case it was because I installed numpy and scipy from the conda-forge channel, which does not install properly the mkl/blas dependencies. So, install the following from the default channel.
Try to create a clean conda environment

conda create -n env_name python=3 numpy scipy cython
source activate env_name
pip install git+https://github.com/theano/theano

Then open a python console and try to import theano only. Hopefully, you will get no warnings. If so, then install pyMC3

pip install git+https://github.com/pymc-devs/pymc3

Also, you could also check if mkl/blas has been properly installed by importing numpy and then type numpy.show_config() (if i remember correctly, i am using my phone now). You should get a list of configurations, and the name mkl/blas should appear several times in there.

1 Like

Since I am using using windows 10, I set a new system environment variable on the control panel:

variable name=MKL_THREADING_LAYER
value=GNU

After I created the new environment variable, I reran the code, but exactly the same error. What am I doing wrong?

Actually, after I rebooted the PC, it finally seems to be working. Thank you very much for the help!

Is this a long term solution at all? Would I have to make a new environment every time?

If you are referring to my post. No, you do not need to create a new environment every time—given that you have managed to install all the dependencies correctly. But, yeah, in general, is good practice to start a any new project from a fresh installed environment.

1 Like

Following up on this a bit further. I found that when I used a new conda environment on Windows I needed to run the command:

conda install -c anaconda libpython

to get Theano to compile nicely.

2 Likes

Thanks a lot, this totally solved the same issue for me.

1 Like