解决RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe

安装d2l包后import tensorflow as tf 时报以下错误

RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe
RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import

解决方法:升级numpy到最新版本

pip install numpy --upgrade

查看版本

pip list |grep numpy 
# numpy    1.23.5

原因分析:

numpy是作为构建依赖项安装的,后来安装d2l包时被固定版本(numpy==1.21.5)替换,导致了上面显示的“编译冲突”

注:tensorflow 和 d2l 可能存在的依赖项冲突如下(目前仅发现numpy对tensorflow有影响,其他三个包对tensorflow暂无)

d2l 0.17.6 requires matplotlib==3.5.1, but you have matplotlib 3.5.2 which is incompatible.
d2l 0.17.6 requires numpy==1.21.5, but you have numpy 1.21.6 which is incompatible.
d2l 0.17.6 requires pandas==1.2.4, but you have pandas 1.4.2 which is incompatible.
d2l 0.17.6 requires requests==2.25.1, but you have requests 2.27.1 which is incompatible.

你可能感兴趣的:(Python-SQL,numpy,python,tensorflow,pip,conda)