2020.12.05|python3.8+tensorflow+anaconda安装(macOS)
步骤如下:
(小白向)
· 打开终端,在上面输入:
conda create -n tensorflow python=3.8
· 然后等执行完毕之后,再执行:
conda activate tensorflow
至此就激活了运行环境。若有(y/n)的选项,输入y
· 然后再执行以进行Tensorflow的安装。
pip install tensorflow
此时在anaconda中已经能看到tensorflow的environment
可在terminal中测试一下,进入python程序后,输入
import tensorflow as tf
若不报错说明安装成功
- 若想在jupyter或Spyder或其他ide中测试是否安装成功的时候(踩坑过后的提示)
可用测试代码:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('hello tensorflow!')
sess = tf.compat.v1.Session()
print(sess.run(hello))
但如果不能在jupyter和spyder中导入,是因为没有将这两个装到tensorflow环境中,执行以下步骤:
打开Anaconda Navigator
点击Environment
选择tensorflow
在右侧下拉列表中,选择not installed
搜索jupyter或spyder,勾选上
点击右下角apply,然后继续安装
然后重新测试
我测试的过程中一直Spyder疯狂报错:An exception has occurred, use %tb to see the full traceback.也没查到解决方案,试了重新安装等一系列方案,最后不知道哪起作用了,重启了一遍发现好用了啊哈哈哈(希望知道的胖友们能指教一下)