【python代码报错解决】ValueError: numpy.dtype size changed, may indicate binary incompatibility.
·
在新的运行环境下解决ValueError: numpy.dtype size changed, may indicate binary incompatibility.
近期在菜鸟教程上学习机器学习时,我在windows系统上的Anaconda运行教程案例代码,出现报错:ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
查了很多博主的帖子,大致知道了是由numpy和pandas版本不匹配引起的。经过多次尝试,我解决的思路是:
- 创建一个新的运行环境(考虑到后面也会继续用机器学习),如:tensorflow;进入新环境安装tensorflow,流程参考:https://blog.csdn.net/thy0000/article/details/122685741,打开Anaconda Prompt,依次运行以下代码,实现tensorflow运行环境创建与激活:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda create -n tensorflow python=3.10
conda activate tensorflow
- 保险起见,在此环境内卸载已有的numpy, scipy, pandas(
pip uninstall numpy scipy pandas) - 然后重新安装numpy, scipy, pandas(
conda install numpy scipy pandas) - 用
pip check命令检查兼容情况(没有亮色的提示出现应该没有问题),然后安装tensorflow:
pip install tensorflow
pip install keras
- 为了将 tensorflow 嵌入到 jupyter中,参考:https://blog.csdn.net/weixin_43682519/article/details/109812553,仍是进入Anaconda Prompt,激活tensorflow环境,依次执行:
conda activate tensorflow
conda install ipython
conda install jupyter
python -m ipykernel install --name tensorflow
jupyter notebook
于是网页会自动打开tensorflow环境下的jupyter notebook,重新运行代码,代码不再提示numpy跟pandas版本不匹配。
更多推荐



所有评论(0)