Theano / Theano

Theano was a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It is being continued as PyTensor: www.github.com/pymc-devs/pytensor

Home Page:https://www.github.com/pymc-devs/pytensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

configparser.NoSectionError: No section: 'blas' (Theano does not run probably on Python 3.9 and Numpy 1.22.2)

bmilde opened this issue · comments

Theano does not run properly on Python 3.9 and Numpy 1.22.2 for me.

I get this error:

Traceback (most recent call last):

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/configparser.py", line 168, in fetch_val_for_key

    return theano_cfg.get(section, option)

  File "/usr/lib/python3.9/configparser.py", line 781, in get

    d = self._unify_values(section, vars)

  File "/usr/lib/python3.9/configparser.py", line 1152, 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/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/configparser.py", line 327, in __get__

    val_str = fetch_val_for_key(self.fullname,

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/configparser.py", line 172, 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/nutzer/projects-2022-04-06/subtitle2go/punctuator2/punctuator.py", line 4, in <module>

    import models

  File "/home/nutzer/projects-2022-04-06/subtitle2go/punctuator2/models.py", line 4, in <module>

    import theano

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/__init__.py", line 124, in <module>

    from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/scan_module/__init__.py", line 41, in <module>

    from theano.scan_module import scan_opt

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/scan_module/scan_opt.py", line 60, in <module>

    from theano import tensor, scalar

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/tensor/__init__.py", line 17, in <module>

    from theano.tensor import blas

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/tensor/blas.py", line 155, in <module>

    from theano.tensor.blas_headers import blas_header_text

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/tensor/blas_headers.py", line 987, in <module>

    if not config.blas.ldflags:

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/configparser.py", line 332, in __get__

    val_str = self.default()

  File "/home/nutzer/projects-2022-04-06/subtitle2go/subtitle2go_env/lib/python3.9/site-packages/theano/configdefaults.py", line 1284, in default_blas_ldflags

    blas_info = np.distutils.__config__.blas_opt_info

AttributeError: module 'numpy.distutils.__config__' has no attribute 'blas_opt_info'

As the error says, there is no blas_opt_info in my numpy config, but replacing line 1284 with:

         blas_info = np.distutils.__config__.blas_opt_info

        =>

        blas_info = np.distutils.__config__.blas_ilp64_opt_info

works and then Theano works as expected! If someone else confirms this error I can do a PR where I'd use a try/except to catch the attribute error on line 1284, with another try to look for blas_ilp64_opt_info if blas_opt_info isn't available. That should work on older and newer numpy versions alike.

I can confirm that this worked for me as well! So strange how that happened.

commented

Same here. Thanks to @bmilde 's fix, which works for me.

Got a similar error using:
pymc3 = "3.11.4"
theano-pymc = "1.1.2"
ubuntu 20.04
python 3.8.16

The above fix doesn't apply.

---------------------------------------------------------------------------
NoSectionError                            Traceback (most recent call last)
File ~/.cache/pypoetry/virtualenvs/ml-XNmo5OXX-py3.8/lib/python3.8/site-packages/theano/configparser.py:238, in TheanoConfigParser.fetch_val_for_key(self, key, delete_key)
    237 try:
--> 238     return self._theano_cfg.get(section, option)
    239 except InterpolationError:

File /usr/lib/python3.8/configparser.py:781, in RawConfigParser.get(self, section, option, raw, vars, fallback)
    780 try:
--> 781     d = self._unify_values(section, vars)
    782 except NoSectionError:

File /usr/lib/python3.8/configparser.py:1149, in RawConfigParser._unify_values(self, section, vars)
   1148     if section != self.default_section:
-> 1149         raise NoSectionError(section) from None
   1150 # 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)
File ~/.cache/pypoetry/virtualenvs/ml-XNmo5OXX-py3.8/lib/python3.8/site-packages/theano/configparser.py:354, in ConfigParam.__get__(self, cls, type_, delete_key)
    353 try:
--> 354     val_str = cls.fetch_val_for_key(self.name, delete_key=delete_key)
...
   2630         # This happen with Python 2.7.3 |EPD 7.3-1 and numpy 1.8.1
   2631         # isort: off
   2632         import numpy.distutils.system_info  # noqa

AttributeError: module 'numpy.distutils.__config__' has no attribute 'blas_opt_info'