g++不可用,如果使用conda:`conda install m2w64-toolchain`

5

在跟随这个神经网络教程过程中,运行test.py文件时,我遇到了以下异常和警告。我已经尝试了之前的建议,但仍然没有解决问题。

WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\ProgramData\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.

任何合适的修复措施都会受到赞赏。
尝试使用“conda install m2w64-toolchain”后,出现了另一个错误,其内容如下:
*You can find the C code in this temporary file: C:\Users\CERTAI~1\AppData\Local\Temp\theano_compilation_error_7bgw9_s9
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py", line 75, in <module>
    raise ImportError()
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py", line 92, in <module>
    raise ImportError()
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\shubhamprojectwork\all Work 2018\kaggle\DeepLearningPython35-master\DeepLearningPython35-master\test.py", line 156, in <module>
    import network3
  File "C:\shubhamprojectwork\all Work 2018\kaggle\DeepLearningPython35-master\DeepLearningPython35-master\network3.py", line 37, in <module>
    import theano
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\__init__.py", line 110, in <module>
    from theano.compile import (
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\__init__.py", line 12, in <module>
    from theano.compile.mode import *
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\mode.py", line 11, in <module>
    import theano.gof.vm
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\vm.py", line 673, in <module>
    from . import lazylinker_c
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py", line 127, in <module>
    preargs=args)
  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\cmodule.py", line 2359, in compile_str
    (status, compile_stderr.replace('\n', '. ')))
Exception: Compilation failed (return status=1): C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `_import_array':
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1470: undefined reference to `__imp_PyExc_ImportError'
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1476: undefined reference to `__imp_PyExc_AttributeError'
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1481: undefined reference to `__imp_PyCapsule_Type'
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1482: undefined reference to `__imp_PyExc_RuntimeError'
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1497: undefined reference to `__imp_PyExc_RuntimeError'
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1505: undefined reference to `__imp_PyExc_RuntimeError'
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1511: undefined reference to `__imp_PyExc_RuntimeError'
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1521: undefined reference to `__imp_PyExc_RuntimeError'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o:C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1533: more undefined references to `__imp_PyExc_RuntimeError' follow
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `NpyCapsule_Check':
. C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include/numpy/npy_3kcompat.h:456: undefined reference to `__imp_PyCapsule_Type'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `unpack_list_of_ssize_t':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:48: undefined reference to `__imp_PyExc_TypeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:58: undefined reference to `__imp_PyExc_IndexError'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `CLazyLinker_init':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:352: undefined reference to `__imp_PyExc_IndexError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:370: undefined reference to `__imp_PyExc_IndexError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:385: undefined reference to `__imp_PyExc_IndexError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:389: undefined reference to `__imp_PyExc_IndexError'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o:C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:393: more undefined references to `__imp_PyExc_IndexError' follow
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `CLazyLinker_init':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:405: undefined reference to `__imp_PyExc_TypeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:420: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:426: undefined reference to `__imp_PyExc_IndexError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:440: undefined reference to `__imp_PyExc_TypeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:444: undefined reference to `__imp__Py_NoneStruct'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `c_call':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:545: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:545: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:545: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:546: undefined reference to `__imp__Py_NoneStruct'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o:C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:546: more undefined references to `__imp__Py_NoneStruct' follow
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `lazy_rec_eval':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:618: undefined reference to `__imp_PyExc_IndexError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:641: undefined reference to `__imp_PyExc_TypeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:649: undefined reference to `__imp_PyExc_ValueError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:657: undefined reference to `__imp_PyExc_IndexError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:708: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:715: undefined reference to `__imp_PyExc_TypeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:721: undefined reference to `__imp_PyExc_TypeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:771: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:771: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:772: undefined reference to `__imp__Py_NoneStruct'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `CLazyLinker_call':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:814: undefined reference to `__imp_PyExc_RuntimeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:826: undefined reference to `__imp_PyExc_RuntimeError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:839: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:839: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:840: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:849: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:849: undefined reference to `__imp__Py_NoneStruct'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o:C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:850: more undefined references to `__imp__Py_NoneStruct' follow
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `CLazyLinker_call':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:894: undefined reference to `__imp_PyExc_AssertionError'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:937: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:937: undefined reference to `__imp__Py_NoneStruct'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:938: undefined reference to `__imp__Py_NoneStruct'
. C:\Users\CERTAI~1\AppData\Local\Temp\ccFdFXU1.o: In function `CLazyLinker_set_allow_gc':
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:973: undefined reference to `__imp_PyBool_Type'
. C:/Users/Certainty1/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-SP0-Intel64_Family_6_Model_142_Stepping_9_GenuineIntel-3.6.1-64/lazylinker_ext/mod.cpp:976: undefined reference to `__imp__Py_TrueStruct'
. collect2.exe: error: ld returned 1 exit status
.* 

“previous suggestion”是什么意思?你尝试过运行conda install m2w64-toolchai吗? - Anthony Kong
是的,@AnthonyKong,在那之后又出现了另一个错误,提示说这些 "collect2.exe: error: ld returned 1 exit status"。 - Shubham Sharma
4个回答

12
根据我的个人经验,连续的错误是由于Windows上没有找到python*.dll文件引起的。您可以通过'conda install libpython'来解决这个问题。

2
我曾经遇到同样的错误。在我的电脑上安装了Python 3.6。我做了以下操作:
1. 卸载并重新安装conda。
2. 使用conda创建一个带有Python 3.5的环境。
3. 在环境中安装m2w64-toolchain。

这样就可以解决问题了!


2

对于那些按照这个页面上所说的一切都已经做了,但仍然遇到以下信息(这意味着您的性能将大大降低)的人:

WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\Users\user\miniconda3\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.

我可以找到消息来源的位置:它在你的Python环境安装路径下的<path_to_your_python_env>/Lib/site-packages/theano/misc/windows.py。在这里,你会在subprocess_Popen方法中找到该字符串。
params['shell'] = True

你需要删除或注释的是调用此方法时检查g++和c++编译器是否存在的部分。使用shell=True参数会在Windows机器上导致未找到错误(该错误被静音处理,所以你永远不会知道 [说实话,我不知道谁决定这样做])。错误很可能是因为传递给subprocess.Popen的系统调用命令被某个符号破坏了:推荐使用字符串args参数来使用shell=True,但Theano的作者并没有遵循这种方式(他们传递列表)。

如果shell为True,则建议将args作为字符串而不是序列传递。

一旦我注释掉了这个字符串并尝试导入Theano/PyMC3,消息就消失了,我可以享受这些惊人工具的最佳性能。

您发布的第一个解决方案的链接无效,还有其他链接吗?我会非常感激您的帮助。 - topotamadre
@CelsaPardoAraujo,我更新了链接,看起来Theano的文档和支持已经转移到PyMC团队下面了。 - Valentin Melnikov

0

我昨天遇到了同样的问题。

Theano需要g++才能正常工作,所以我不得不下载并安装它。

请按照以下链接中的说明进行下载和安装:

http://www.instructables.com/id/How-to-Install-MinGW-GCCG-Compiler-in-Windows-XP78/

在将路径添加到我的环境变量后,我卸载并重新安装了Anaconda。

我为Python 3.5创建了一个新的环境,激活它后,按照这里的说明安装了Theano。

http://deeplearning.net/software/theano/install_windows.html

他们的操作导致我的Python版本降级到了2.7

然后我进行了以下操作:

1:pip install future 2:pip install pillow 3:conda install nb_conda_kernels 4:pip install future --upgrade 5:添加环境变量 - MKL_THREADING_LAYER=GNU 6:重新启动终端,一切正常。

对于后续的环境,我不需要再执行这些初始步骤。在激活Python 3.5环境后,执行conda install theano即可完成所有设置。

希望能对您有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接