You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apple Macbook M1环境下无法导入Tensorflow的问题求助

解决Mac上导入TensorFlow时的版本兼容错误

错误信息

TypeError: Unable to convert function return value to a Python type! The signature was
    () -> handle
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
ImportError: numpy.core._multiarray_umath failed to import
ImportError: numpy.core.umath failed to import

操作步骤

  • 创建conda环境:conda create --name myenv python
  • 激活环境:conda activate myenv
  • 安装Apple提供的TensorFlow依赖:conda install -c apple tensorflow-deps
  • 安装TensorFlow macOS版本:python -m pip install tensorflow-macos
  • 安装TensorFlow Metal插件:python -m pip install tensorflow-metal

当前环境包列表

absl-py                   1.3.0                    pypi_0    pypi
astunparse                1.6.3                    pypi_0    pypi
blas                      1.0                    openblas  
bzip2                     1.0.8                h620ffc9_4  
c-ares                    1.18.1               h1a28f6b_0  
ca-certificates           2022.10.11           hca03da5_0  
cachetools                5.2.0                    pypi_0    pypi
certifi                   2022.9.24       py310hca03da5_0  
charset-normalizer        2.1.1                    pypi_0    pypi
flatbuffers               22.10.26                 pypi_0    pypi
gast                      0.4.0                    pypi_0    pypi
google-auth               2.14.0                   pypi_0    pypi
google-auth-oauthlib      0.4.6                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpcio                    1.42.0          py310h95c9599_0  
h5py                      3.6.0           py310h181c318_0  
hdf5                      1.12.1               h160e8cb_2  
idna                      3.4                      pypi_0    pypi
keras                     2.10.0                   pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
krb5                      1.19.2               h3b8d789_0  
libclang                  14.0.6                   pypi_0    pypi
libcurl                   7.85.0               hc6d1d07_0  
libcxx                    14.0.6               h848a8c0_0  
libedit                   3.1.20210910         h1a28f6b_0  
libev                     4.33                 h1a28f6b_1  
libffi                    3.4.2                hc377ac9_4  
libgfortran               5.0.0           11_3_0_hca03da5_28  
libgfortran5              11.3.0              h009349e_28  
libnghttp2                1.46.0               h95c9599_0  
libopenblas               0.3.21               h269037a_0  
libssh2                   1.10.0               hf27765b_0  
llvm-openmp               14.0.6               hc6e5704_0  
markdown                  3.4.1                    pypi_0    pypi
markupsafe                2.1.1                    pypi_0    pypi
ncurses                   6.3                  h1a28f6b_3  
numpy                     1.22.3          py310hdb36b11_0  
numpy-base                1.22.3          py310h5e3e9f0_0  
oauthlib                  3.2.2                    pypi_0    pypi
openssl                   1.1.1q               h1a28f6b_0  
opt-einsum                3.3.0                    pypi_0    pypi
packaging                 21.3                     pypi_0    pypi
pip                       22.2.2          py310hca03da5_0  
protobuf                  3.19.6                   pypi_0    pypi
pyasn1                    0.4.8                    pypi_0    pypi
pyasn1-modules            0.2.8                    pypi_0    pypi
pyparsing                 3.0.9                    pypi_0    pypi
python                    3.10.6               hbdb9e5c_1  
readline                  8.2                  h1a28f6b_0  
requests                  2.28.1                   pypi_0    pypi
requests-oauthlib         1.3.1                    pypi_0    pypi
rsa                       4.9                      pypi_0    pypi
setuptools                65.5.0          py310hca03da5_0  
six                       1.16.0             pyhd3eb1b0_1  
sqlite                    3.39.3               h1058600_0  
tensorboard               2.10.1                   pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1                    pypi_0    pypi
tensorflow-deps           2.9.0                         0    apple
tensorflow-estimator      2.10.0                   pypi_0    pypi
tensorflow-macos          2.10.0                   pypi_0    pypi
tensorflow-metal          0.6.0                    pypi_0    pypi
termcolor                 2.1.0                    pypi_0    pypi
tk                        8.6.12               hb8d0fd4_0  
typing-extensions         4.4.0                    pypi_0    pypi
tzdata                    2022f                h04d1e81_0  
urllib3                   1.26.12                  pypi_0    pypi
werkzeug                  2.2.2                    pypi_0    pypi
wheel                     0.37.1             pyhd3eb1b0_0  
wrapt                     1.14.1                   pypi_0    pypi
xz                        5.2.6                h1a28f6b_0  
zlib                      1.2.13               h5a0b063_0  

解决方案

错误核心是numpy版本不兼容:提示中的API version 0x10对应numpy 1.23及以上版本,但当前环境numpy为1.22.3(API版本0xf),导致TensorFlow编译模块无法适配。执行以下步骤修复:

  1. 激活conda环境:
conda activate myenv
  1. 升级numpy到兼容版本(推荐1.23.5,适配tensorflow-macos 2.10):
pip install --upgrade numpy==1.23.5
  1. 验证修复效果:
python -c "import tensorflow as tf; print(tf.__version__)"

若仍有问题,可尝试重新安装tensorflow-deps后再升级numpy:

conda install -c apple tensorflow-deps --force-reinstall
pip install --upgrade numpy==1.23.5

内容的提问来源于stack exchange,提问作者EddLuiz12

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 12:31:00