gpt4 book ai didi

python - 导入 keras 和 tensorflow 时出错

转载 作者:行者123 更新时间:2023-12-04 15:24:53 27 4
gpt4 key购买 nike

我使用了 from keras.layers import dot 并返回了这个错误:

c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
17 try:
---> 18 fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
19 except ImportError:

c:\users\prashasti\appdata\local\programs\python\python37-32\lib\imp.py in find_module(name, path)
295 else:
--> 296 raise ImportError(_ERR_MSG.format(name), name=name)
297

ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last)
c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
40 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 41 from tensorflow.python.pywrap_tensorflow_internal import *
42 from tensorflow.python.pywrap_tensorflow_internal import __version__

c:\users\prashasti\appdata\local\programs\python\python37-32\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\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
19 except ImportError:
---> 20 import _pywrap_tensorflow_internal
21 return _pywrap_tensorflow_internal

ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)
c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\keras\__init__.py in <module>
2 try:
----> 3 from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
4 except ImportError:

c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\__init__.py in <module>
23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *
25 # pylint: enable=wildcard-import

c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\__init__.py in <module>
48
---> 49 from tensorflow.python import pywrap_tensorflow
50

c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
51 above this error message when asking for help.""" % traceback.format_exc()
---> 52 raise ImportError(msg)
53

ImportError: Traceback (most recent call last):
File "c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
File "c:\users\prashasti\appdata\local\programs\python\python37-32\lib\imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)
<ipython-input-14-884a93be26a0> in <module>
----> 1 from keras.layers import dot

c:\users\prashasti\appdata\local\programs\python\python37-32\lib\site-packages\keras\__init__.py in <module>
4 except ImportError:
5 raise ImportError(
----> 6 'Keras requires TensorFlow 2.2 or higher. '
7 'Install TensorFlow via `pip install tensorflow`')
8

ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`

我升级了tensorflow。也重新安装了它,但没有用。

最佳答案

我有 CUDA 10.0 和 cuDNN 7.6.4我也收到以下错误

ImportError:Keras 需要 TensorFlow 2.2 或更高版本。通过 pip install tensorflow

安装 TensorFlow

我所做的是首先卸载所有东西,比如没有 python、没有 anaconda、没有虚拟环境。

然后执行以下步骤:

  1. 将 anaconda win 64 与 python 3.7 作为一个软件包安装
  2. Anaconda安装后,需要设置路径C:\Users\用户名\Anaconda3\Scripts
  3. 更新点数
  4. conda 更新
  5. conda create -n tf20 python=3.7
  6. pip 安装 numpy
  7. pip 安装 "tensorflow>=1.15,<2.0"
  8. pip install "tensorflow-gpu>=1.15,<2.0"(如果需要 GPU 支持)
  9. pip install keras(安装最新的2.4.2)
  10. pip install --upgrade tensorflow-hub
  11. pip install keras==2.2.4(降级到2.2.4)

现在 keras 使用 tensorflow 1.15 运行也许你可以在第 9 步中执行 pip install keras==2.2.4 并删除第 11 步。在卸载所有内容之前,只需尝试从第 2 步开始的上述步骤一次。如果可行,您可以节省时间。祝你好运:)

如果这对您有用,请告诉我。

-谢谢

关于python - 导入 keras 和 tensorflow 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62482404/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com