可能是安装了与TensorFlow不兼容的Python版本,可以尝试重新安装tensorflow-macos,并指定正确的Python版本。例如,在macOS Catalina上,需要指定使用Python 3.8版本:
sudo pip3 install tensorflow-macos==2.4.0rc0 --use-feature=2020-resolver --ignore-installed numpy pandas tensorflow
sudo python3.8 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
如果在Jupyter Notebook中使用TensorFlow,则需要在Notebook中指定正确的Python内核:
import sys
!{sys.executable} -m ipykernel install --user --name=tensorflow_env
然后,在Notebook中选择名为“tensorflow_env”的内核即可。