Python keras“;在不同的conda环境中发生错误

Python keras“;在不同的conda环境中发生错误,python,keras,conda,Python,Keras,Conda,我正在使用python 3.7,win 10。我已经使用conda定义了一个新环境,不幸的是,当我使用 conda activate the "name of my environment" 我想在单元格中运行Keras import命令时使用我的上一个笔记本 from keras.preprocessing.text import Tokenizer from keras.preprocessing.sequence import pad_sequences from keras impo

我正在使用python 3.7,win 10。我已经使用conda定义了一个新环境,不幸的是,当我使用

conda activate the "name of my environment"

我想在单元格中运行Keras import命令时使用我的上一个笔记本

from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras import metrics
import keras.backend as K
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.layers import Embedding
from keras.layers import Conv1D, MaxPooling1D
我面临着关于Keras或TensorFlow的错误

错误是这样的:

Using TensorFlow backend.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     57 
---> 58   from tensorflow.python.pywrap_tensorflow_internal import *
     59   from tensorflow.python.pywrap_tensorflow_internal import __version__

c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in <module>
     27             return _mod
---> 28     _pywrap_tensorflow_internal = swig_import_helper()
     29     del swig_import_helper

c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
     23             try:
---> 24                 _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
     25             finally:

~\Anaconda3\envs\envc\lib\imp.py in load_module(name, file, filename, details)
    241         else:
--> 242             return load_dynamic(name, filename, file)
    243     elif type_ == PKG_DIRECTORY:

~\Anaconda3\envs\envc\lib\imp.py in load_dynamic(name, path, file)
    341             name=name, loader=loader, origin=path)
--> 342         return _load(spec)
    343 

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-15-d5531b57a346> in <module>
----> 1 from keras.preprocessing.text import Tokenizer
      2 from keras.preprocessing.sequence import pad_sequences
      3 from keras import metrics
      4 import keras.backend as K
      5 from keras.preprocessing import sequence

c:\users\moha\anaconda3\lib\site-packages\keras\__init__.py in <module>
      1 from __future__ import absolute_import
      2 
----> 3 from . import utils
      4 from . import activations
      5 from . import applications

c:\users\moha\anaconda3\lib\site-packages\keras\utils\__init__.py in <module>
      4 from . import data_utils
      5 from . import io_utils
----> 6 from . import conv_utils
      7 
      8 # Globally-importable utils.

c:\users\moha\anaconda3\lib\site-packages\keras\utils\conv_utils.py in <module>
      7 from six.moves import range
      8 import numpy as np
----> 9 from .. import backend as K
     10 
     11 

c:\users\moha\anaconda3\lib\site-packages\keras\backend\__init__.py in <module>
     87 elif _BACKEND == 'tensorflow':
     88     sys.stderr.write('Using TensorFlow backend.\n')
---> 89     from .tensorflow_backend import *
     90 else:
     91     # Try and load external backend.

c:\users\moha\anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py in <module>
      3 from __future__ import print_function
      4 
----> 5 import tensorflow as tf
      6 from tensorflow.python.framework import ops as tf_ops
      7 from tensorflow.python.training import moving_averages

c:\users\moha\anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     22 
     23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 
     26 from tensorflow._api.v1 import app

c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
     47 import numpy as np
     48 
---> 49 from tensorflow.python import pywrap_tensorflow
     50 
     51 # Protocol buffers

c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     72 for some common reasons and solutions.  Include the entire stack trace
     73 above this error message when asking for help.""" % traceback.format_exc()
---> 74   raise ImportError(msg)
     75 
     76 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

ImportError: Traceback (most recent call last):
  File "c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "c:\users\moha\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Users\moha\Anaconda3\envs\envc\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\moha\Anaconda3\envs\envc\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help
使用TensorFlow后端。
---------------------------------------------------------------------------
ImportError回溯(最近一次呼叫最后一次)
c:\users\moha\anaconda3\lib\site packages\tensorflow\python\pywrap\u tensorflow.py in
57
--->58来自tensorflow.python.pywrap\u tensorflow\u内部导入*
59来自tensorflow.python.pywrap\u tensorflow\u内部导入\u版本__
c:\users\moha\anaconda3\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py in
27返回模式
--->28_pywrap_tensorflow_internal=swig_import_helper()
29 del swig_导入帮助程序
swig\u import\u helper()中的c:\users\moha\anaconda3\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py
23尝试:
--->24_mod=imp.load_模块(“pywrap_tensorflow_internal”,fp,路径名,描述)
25最后:
加载模块中的~\Anaconda3\envs\envc\lib\imp.py(名称、文件、文件名、详细信息)
241其他:
-->242返回加载动态(名称、文件名、文件)
243 elif类型=PKG\u目录:
动态加载中的~\Anaconda3\envs\envc\lib\imp.py(名称、路径、文件)
341名称=名称,加载器=加载器,原点=路径)
-->342返回荷载(规范)
343
ImportError:DLL加载失败:找不到指定的模块。
在处理上述异常期间,发生了另一个异常:
ImportError回溯(最近一次呼叫最后一次)
在里面
---->1来自keras.preprocessing.text导入标记器
2来自keras.preprocessing.sequence导入pad_序列
3来自keras进口指标
4将keras.backend导入为K
5来自keras.preprocessing导入序列
c:\users\moha\anaconda3\lib\site packages\keras\\uuuuu init\uuuuuuuu.py in
1来自未来导入绝对导入
2.
---->3从。导入UTIL
4来自。导入激活
5从。导入应用程序
c:\users\moha\anaconda3\lib\site packages\keras\utils\\uuuuu init\uuuuuuuuu.py in
4来自。导入数据工具
5从。导入io_utils
---->6从。导入conv_utils
7.
8#全球重要UTIL。
c:\users\moha\anaconda3\lib\site packages\keras\utils\conv\u utils.py in
7从6.5移到进口范围
8作为np进口numpy
---->9从。。将后端导入为K
10
11
c:\users\moha\anaconda3\lib\site packages\keras\backend\\uuuuu init\uuuuuuuuuu.py in
87 elif\u后端=='tensorflow':
88 sys.stderr.write('使用TensorFlow后端。\n')
--->89来自tensorflow_后端导入*
90其他:
91#尝试加载外部后端。
c:\users\moha\anaconda3\lib\site packages\keras\backend\tensorflow\u backend.py in
3来自未来导入打印功能
4.
---->5导入tensorflow作为tf
6从tensorflow.python.framework将ops导入为tf_ops
7从tensorflow.python.training导入移动平均值
c:\users\moha\anaconda3\lib\site packages\tensorflow\\uuuu init\uuuuu.py in
22
23#pylint:disable=g-bad-import-order
--->24从tensorflow.python导入pywrapu tensorflow35; pylint:disable=未使用的导入
25
26来自tensorflow.\u api.v1导入应用程序
c:\users\moha\anaconda3\lib\site packages\tensorflow\python\ \uuuuu init\uuuuuuu.py in
47作为np的进口numpy
48
--->49从tensorflow.python导入pywrap\u tensorflow
50
51#协议缓冲区
c:\users\moha\anaconda3\lib\site packages\tensorflow\python\pywrap\u tensorflow.py in
72.一些常见的原因和解决方案。包括整个堆栈跟踪
73在请求帮助时显示此错误消息。“%traceback.format_exc()
--->74.恐怖分子(味精)
75
76#pylint:enable=通配符导入,g-import-not-at-top,未使用的导入,行太长
ImportError:回溯(最近一次呼叫上次):
文件“c:\users\moha\anaconda3\lib\site packages\tensorflow\python\pywrap\u tensorflow.py”,第58行,在
从tensorflow.python.pywrap\u tensorflow\u内部导入*
文件“c:\users\moha\anaconda3\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”,第28行,在
_pywrap\u tensorflow\u internal=swig\u import\u helper()
文件“c:\users\moha\anaconda3\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”,第24行,在swig\u import\u helper中
_mod=imp.load_模块(“pywrap_tensorflow_internal”,fp,路径名,描述)
文件“C:\Users\moha\Anaconda3\envs\envc\lib\imp.py”,第242行,在加载模块中
返回加载动态(名称、文件名、文件)
文件“C:\Users\moha\Anaconda3\envs\envc\lib\imp.py”,第342行,在load\u dynamic中
返回负载(规格)
ImportError:DLL加载失败:找不到指定的模块。
未能加载本机TensorFlow运行时。
看见https://www.tensorflow.org/install/errors
由于一些常见的原因和解决方案。包括整个堆栈跟踪
以上是请求帮助时的错误消息
我在这里尝试了不同的解决方案

不工作或面临其他错误

你有什么简单的解决办法吗


我需要声明它在我的主环境中工作,我认为它主要与后端TensorFlow的Keras有关…

有些可疑,因为你在你的环境中,但是你的
tf
似乎是从
c:\users\moha\anaconda3\lib\site包加载的,除非你是我,否则不应该检查它在您的基本环境中。您是否可以检查您的环境中是否安装了tensorflow,以及是否正确设置了
PYTHONPATH
?我猜您在某些时候遵循了一些过时的建议,并手动添加了
C:\User