Theano fails due to NumPy Fortran mixup under Ubuntu

后端 未结 4 819
灰色年华
灰色年华 2021-01-01 23:21

I installed Theano on my machine, but the nosetests break with a Numpy/Fortran related error message. For me it looks like Numpy was compiled with a different Fortran versio

相关标签:
4条回答
  • 2021-01-02 00:01

    Have you tried to recompile NumPy from the sources?

    I'm not familiar with the Ubuntu package system, so I can't check what's in your dist-packages/numpy. With a clean archive of the NumPy sources, you should have a setup.py at the same level as the directories numpy, tools and benchmarks (among others). I'm pretty sure that's the one you want to use for a python setup.py build.

    [EDIT]

    Now that you have recompiled numpy with the proper --fcompiler option, perhaps could you try to do the same with Theano, that is, compiling directly from sources without relying on a apt-get or even pip. You should have a better control on the build process that way, which will make debugging/trying to find a solution easier.

    0 讨论(0)
  • 2021-01-02 00:08

    I had the same problem, and after reviewing the source code, user212658's answer seemed like it would work (I have not tried it). I then looked for a way to deploy user212658's hack without modifying the source code.

    Put these lines in your theanorc file:

    [blas]
    ldflags = -lblas -lgfortran
    

    This worked for me.

    0 讨论(0)
  • 2021-01-02 00:16

    A better fix is to remove atlas and install openblas. openblas is faster then atlas. Also, openblas don't request gfortran and is the one numpy was linked with. So it will work out of the box.

    0 讨论(0)
  • 2021-01-02 00:22

    I had the same problem. The solution I found is to add a hack in theano/gof/cmodule.py to link against gfortran whenever 'blas' is in the libs. That fixed it.

    class GCC_compiler(object):
       ...
        @staticmethod
        def compile_str(module_name, src_code, location=None,
                        include_dirs=None, lib_dirs=None, libs=None,
                        preargs=None):
            ...
            cmd.extend(['-l%s' % l for l in libs])
            if 'blas' in libs:
                cmd.append('-lgfortran')
    
    0 讨论(0)
提交回复
热议问题