解决import tensorflow as tf 出错的原因

作者:njzhuming 时间:2023-06-26 23:53:21 

笔者在运行 import tensorflow as tf时出现下面的错误,但在运行import tensorflow时没有出错。


>>> import tensorflow as tf
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xa
ImportError: numpy.core.multiarray failed to import
ImportError: numpy.core.umath failed to import
ImportError: numpy.core.umath failed to import
2018-12-09 01:22:17.925262: F tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullp
tr

后运行keras初级教程上的以下代码也报错:


# univariate lstm example
from numpy import array
from keras.models import Sequential
from keras.layers import LSTM
from keras.layers import Dense
# define dataset
X = array([[10, 20, 30], [20, 30, 40], [30, 40, 50], [40, 50, 60]])
y = array([40, 50, 60, 70])
# reshape from [samples, timesteps] into [samples, timesteps, features]
X = X.reshape((X.shape[0], X.shape[1], 1))
# define model
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(3, 1)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
# fit model
model.fit(X, y, epochs=1000, verbose=0)
# demonstrate prediction
x_input = array([50, 60, 70])
x_input = x_input.reshape((1, 3, 1))
yhat = model.predict(x_input, verbose=0)
print(yhat)

经查阅资料后,安装以下网站的pip install tf-nightly

https://pypi.org/project/tf-nightly/

安装完成后运行上面所有代码就OK了,特此分享!

来源:https://blog.csdn.net/njzhuming/article/details/84901409

标签:import,tensorflow
0
投稿

猜你喜欢

  • python将字符串转换成json的方法小结

    2023-11-17 23:58:57
  • Python中ArcPy栅格裁剪栅格(批量对齐栅格图像范围并统一行数与列数)

    2021-02-19 21:12:48
  • 简单分析Python中用fork()函数生成的子进程

    2021-11-24 02:48:02
  • 在Vue中用canvas实现二维码和图片合成海报的方法

    2024-05-09 09:53:23
  • ORACLE常见错误代码的分析与解决(三)

    2024-01-17 19:17:57
  • python的函数和方法(上)

    2021-02-04 11:46:16
  • Python中的turtle画箭头,矩形,五角星

    2023-11-22 13:38:12
  • Python的for和break循环结构中使用else语句的技巧

    2022-07-02 16:59:26
  • Python机器学习之基础概述

    2021-07-18 19:07:59
  • MySql主从复制实现原理及配置

    2024-01-16 01:37:39
  • docker django无法访问redis容器的解决方法

    2021-10-05 05:48:22
  • 对python中的乘法dot和对应分量相乘multiply详解

    2021-01-14 15:54:58
  • python实现整数的二进制循环移位

    2022-09-08 23:11:39
  • 基于Python实现对比Exce的工具

    2022-12-04 17:44:44
  • 动态加载JavaScript的小实践

    2009-11-12 12:38:00
  • Python通过zookeeper实现分布式服务代码解析

    2021-09-11 11:09:48
  • JS 实现计算器详解及实例代码(一)

    2024-04-17 10:08:57
  • Python绘制灯笼的示例代码

    2022-02-24 23:10:35
  • 设置SQLServer数据库中某些表为只读的多种方法分享

    2012-07-11 15:41:05
  • Python 经典贪心算法之Prim算法案例详解

    2024-01-01 18:18:27
  • asp之家 网络编程 m.aspxhome.com