在theano建议上安装了g ++。现在theano不起作用

时间:2019-02-15 16:34:45

标签: anaconda theano-cuda

Windows下,成功安装tensorflow gpu,keras gpu之后,我使用以下方法安装了theano gpu

conda install theano pygpu

一切仍然正常,tensorflow gpu, keras gpu等。我在theano中运行了一个简单示例,并在jupyter中执行了该行,

import numpy
import theano.tensor as T
from theano import function

它发出警告:

WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\Anaconda3\lib\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

因此,我决定按照建议使用g++安装conda

conda install m2w64-toolchain

现在,当我在theano中运行同一行时,

import numpy
import theano.tensor as T

我得到一个错误:

You can find the C code in this temporary file: C:\Users\IVANFI~1\AppData\Local\Temp\theano_compilation_error_fq4oz7pp
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
C:\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)
C:\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-12-29f575dfe616> in <module>()
      1 import numpy
----> 2 import theano.tensor as T

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

C:\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 *

C:\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

C:\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):

C:\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')

C:\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)
   2394             # difficult to read.
   2395             raise Exception('Compilation failed (return status=%s): %s' %
-> 2396                             (status, compile_stderr.replace('\n', '. ')))
   2397         elif config.cmodule.compilation_warning and compile_stderr:
   2398             # Print errors just below the command line.

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

删除

conda remove m2w64-toolchain

没有帮助。 theano似乎已永久损坏。 如何恢复theano正常工作?

2 个答案:

答案 0 :(得分:0)

要恢复为原始的基于NumPy的模式,只需将theano配置为不使用编译器。

使用以下方法创建C:\\Users\\username\\.theanorc.txt文件:

[global]
cxx=

More about theano config

答案 1 :(得分:0)

我在这个话题上浪费了很多时间。首先,确保Theano使用编译器在普通CPU上运行。 使用m2w64-toolchain反复杀死有关theano的完整anaconda设置。您不仅需要卸载Anaconda,还需要卸载所有剩余的工件。 XavierDupré的article使我步入正轨。 因此,对于CPU仅使用conda安装命令即可:

conda install -c anaconda libpython
conda install -c anaconda mingw
conda install -c anaconda Theano
conda install -c anaconda  pymc3

至少这时您具有适当的编译环境。

BR,亚历克斯