【问题标题】:Keras installed but not workingKeras 已安装但无法正常工作
【发布时间】:2017-10-05 06:32:33
【问题描述】:

我使用 keras 和 theano 作为后端在 windows 10 上构建神经网络。我的 python 版本是 2.7。问题是当我尝试使用 keras 时,我不断收到路径错误。

$python
>>import keras

给我错误

Problem occurred during compilation with the command line below:
"g++" -shared -g -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -I"C:\Python27\lib\site-packages\numpy\core\include" -I"C:\Python27\include" -I"C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof" -L"C:\Python27\libs" -L"C:\Python27" -o C:\Users\Patrick\AppData\Local\Theano\compiledir_Windows-10-10.0.14393-Intel64_Family_6_Model_61_Stepping_4_GenuineIntel-2.7.11-64\lazylinker_ext\lazylinker_ext.pyd C:\Users\Patrick\AppData\Local\Theano\compiledir_Windows-10-10.0.14393-Intel64_Family_6_Model_61_Stepping_4_GenuineIntel-2.7.11-64\lazylinker_ext\mod.cpp -lpython27
The system cannot find the path specified.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\__init__.py", line 3, in <module>
    from . import activations
  File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\activations.py", line 4, in <module>
    from . import backend as K
  File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\backend\__init__.py", line 70, in <module>
    from .theano_backend import *
  File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\backend\theano_backend.py", line 3, in <module>
    import theano
  File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\__init__.py", line 66, in <module>
    from theano.compile import (
  File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\compile\__init__.py", line 10, in <module>
    from theano.compile.function_module import *
  File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\compile\function_module.py", line 21, in <module>
    import theano.compile.mode
  File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\compile\mode.py", line 10, in <module>
    import theano.gof.vm
  File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof\vm.py", line 662, in <module>
    from . import lazylinker_c
  File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof\lazylinker_c.py", line 127, in <module>
    preargs=args)
  File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof\cmodule.py", line 2316, in compile_str
    (status, compile_stderr.replace('\n', '. ')))
. ception: Compilation failed (return status=1): The system cannot find the path specified.
>>>

我可以告诉我需要添加到我的系统变量路径(至少我是这么认为的......)但无论我添加什么,我仍然会收到错误。我已经尝试添加

C:\Python27\lib
C:\Python27\lib\site-packages

基本上它所说的任何路径都无法指定。需要注意的是,我在安装 scipy 时遇到了很多麻烦,并且必须从 http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy 获取 .whl 文件,不确定这是否有帮助。那是我的问题。

【问题讨论】:

  • 它可能找不到g++,你有没有安装它,在哪里?那条路径在 PATH 中吗?
  • 如果你没有安装 g++,试试 MinGW - 我在这里找到了我的:nuwen.net/mingw.html

标签: windows python-2.7 scipy keras theano


【解决方案1】:

我的建议是使用 conda 在单独的环境中使用 keras。
假设您要创建一个名为“myenv”的环境
1.打开 Anaconda 提示并输入以下内容:

conda create --name myenv

2.激活环境:

conda activate myenv

3.现在可以安装keras和其他依赖了:

pip install keras

如下安装tensorflow。

pip install tensorflow==2.0.0

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题,并通过删除其他 python 版本来解决。确保您只安装了 1 个 python。如果有多个,有时事情就不能很好地工作。

    【讨论】:

      猜你喜欢
      • 2011-12-18
      • 2015-02-05
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多