Getting Theano Working

Hi, I have been trying to successfully run a program that uses a theano Op. When I follow the instructions here: Installation Guide (Linux) · pymc-devs/pymc Wiki · GitHub I get the following error when I import theano:

 You can find the C code in this temporary file: /tmp/theano_compilation_error_mxce2qm8
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/theano/gof/lazylinker_c.py", line 81, in <module>
    actual_version, force_compile, _need_reload))
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:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/theano/gof/lazylinker_c.py", line 105, in <module>
    actual_version, force_compile, _need_reload))
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:

Traceback (most recent call last):
  File "testintegrate.py", line 2, in <module>
    import theano
  File "/usr/local/lib/python3.5/site-packages/theano/__init__.py", line 110, in <module>
    from theano.compile import (
  File "/usr/local/lib/python3.5/site-packages/theano/compile/__init__.py", line 12, in <module>
    from theano.compile.mode import *
  File "/usr/local/lib/python3.5/site-packages/theano/compile/mode.py", line 11, in <module>
    import theano.gof.vm
  File "/usr/local/lib/python3.5/site-packages/theano/gof/vm.py", line 674, in <module>
    from . import lazylinker_c
  File "/usr/local/lib/python3.5/site-packages/theano/gof/lazylinker_c.py", line 140, in <module>
    preargs=args)
  File "/usr/local/lib/python3.5/site-packages/theano/gof/cmodule.py", line 2411, in compile_str
    (status, compile_stderr.replace('\n', '. ')))
Exception: Compilation failed (return status=1): /usr/bin/ld: /usr/local/lib/libpython3.5m.a(ceval.o): relocation R_X86_64_PC32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC. /usr/bin/ld: final link failed: Bad value. collect2: error: ld returned 1 exit status.

I would try with PyMC v4.

Hi @twiecki - I think there was something wrong with my python installation - I started using a lot of python when 3.5 was new and so I didn’t know to use venvs, where to place packages, etc. It is a mess. I reinstalled python 3.5 through conda and that fixed this problem. However, when I run the same script to import theano, I get the error

Intel MKL FATAL ERROR: Cannot load libmkl_core.so.

This seems to be tied up with the mkl or mkl-service package and theano. Some Stack Exchange comments say you can delete these, but that seems to conflict with numpy - numpy must need these libraries to work and I need numpy for my code. Any ideas?

@twiecki I have tried now with a fresh conda environment with python 3.5. I conda installed scipy, numpy and scipy. I then pip installed theano from git and pymc4 from git. This still gives the same MKL error.

Regardless of the rest, note that we no longer support python 3.5 officially

@ricardoV94 Ah - I was working off of the documentation here.

Okay - using python 3.10.4 + pymc3 led to one error:

File "/home/adrian/Desktop/testintegrate.py", line 8, in <module> class Integrate(theano.Op): AttributeError: module 'theano' has no attribute 'Op'. Did you mean: 'p'?

and 3.10.4 + pymc4 led to a different error:

` File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/configparser.py”, line 238, in fetch_val_for_key
return self._theano_cfg.get(section, option)
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/configparser.py”, line 782, in get
d = self._unify_values(section, vars)
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/configparser.py”, line 1153, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘blas’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/configparser.py”, line 354, in get
val_str = cls.fetch_val_for_key(self.name, delete_key=delete_key)
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/configparser.py”, line 242, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas__ldflags’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/adrian/Desktop/testintegrate.py”, line 2, in
import theano
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/init.py”, line 83, in
from theano import scalar, tensor
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/tensor/init.py”, line 20, in
from theano.tensor import nnet # used for softmax, sigmoid, etc.
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/tensor/nnet/init.py”, line 3, in
from . import opt
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/tensor/nnet/opt.py”, line 32, in
from theano.tensor.nnet.conv import ConvOp, conv2d
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/tensor/nnet/conv.py”, line 20, in
from theano.tensor import blas
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/tensor/blas.py”, line 163, in
from theano.tensor.blas_headers import blas_header_text, blas_header_version
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/tensor/blas_headers.py”, line 1016, in
if not config.blas__ldflags:
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/configparser.py”, line 358, in get
val_str = self.default()
File “/home/adrian/anaconda3/envs/fresh_env/lib/python3.10/site-packages/theano/link/c/cmodule.py”, line 2621, in default_blas_ldflags
blas_info = numpy.distutils.config.blas_opt_info
AttributeError: module ‘numpy.distutils.config’ has no attribute ‘blas_opt_info’
`

I am trying to run the integration script here on a simple polynomial integral.

PyMC 4 uses aesara, not theano

Thanks, okay. Which version is better suited for my end goal described here? From the responses, it seems like I need aesara to solve a polynomial expression and theano to use the solution as a limit of integration.

Aesara is a successor to Theano, you should be able to do everything with Aesara, and you cannot mix the two libraries

Okay, I’ve pip installed aesara from the repo here. Now when working in a conda environment, I get the following error when I try to import the new package:

> [Errno 2] No such file or directory: '/home/adrian/anaconda3/envs/fresh_env/bin/x86_64-conda-linux-gnu-cc'

Solved by

> conda install gxx_linux-64

per python 2.7 - unable to execute 'x86_64-conda_cos6-linux-gnu-gcc': No such file or directory (pysam installation) - Stack Overflow

1 Like