解决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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python将字符串转换成json的方法小结
2023-11-17 23:58:57
Python中ArcPy栅格裁剪栅格(批量对齐栅格图像范围并统一行数与列数)
2021-02-19 21:12:48
![](https://img.aspxhome.com/file/2023/9/81799_0s.png)
简单分析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
![](https://img.aspxhome.com/file/2023/4/64274_0s.jpg)
Python中的turtle画箭头,矩形,五角星
2023-11-22 13:38:12
![](https://img.aspxhome.com/file/2023/4/97734_0s.png)
Python的for和break循环结构中使用else语句的技巧
2022-07-02 16:59:26
Python机器学习之基础概述
2021-07-18 19:07:59
![](https://img.aspxhome.com/file/2023/8/89408_0s.png)
MySql主从复制实现原理及配置
2024-01-16 01:37:39
![](https://img.aspxhome.com/file/2023/9/122939_0s.png)
docker django无法访问redis容器的解决方法
2021-10-05 05:48:22
![](https://img.aspxhome.com/file/2023/4/112604_0s.jpg)
对python中的乘法dot和对应分量相乘multiply详解
2021-01-14 15:54:58
python实现整数的二进制循环移位
2022-09-08 23:11:39
![](https://img.aspxhome.com/file/2023/1/97681_0s.jpg)
基于Python实现对比Exce的工具
2022-12-04 17:44:44
![](https://img.aspxhome.com/file/2023/4/70894_0s.png)
动态加载JavaScript的小实践
2009-11-12 12:38:00
![](https://img.aspxhome.com/file/UploadPic/200911/12/yui-loader-bug-in-ie-58s.png)
Python通过zookeeper实现分布式服务代码解析
2021-09-11 11:09:48
JS 实现计算器详解及实例代码(一)
2024-04-17 10:08:57
![](https://img.aspxhome.com/file/2023/5/136355_0s.png)
Python绘制灯笼的示例代码
2022-02-24 23:10:35
设置SQLServer数据库中某些表为只读的多种方法分享
2012-07-11 15:41:05
Python 经典贪心算法之Prim算法案例详解
2024-01-01 18:18:27
![](https://img.aspxhome.com/file/2023/2/79482_0s.png)