清华镜像源安装
pip install tensorflow-gpu==1.12.0 -i https://pypi.tuna.tsinghua.edu.cn/simple #可改成任意版本
CPU版本安装
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
Pycharm环境配置
(一)导入TensorFlow模块测试
import tensorflow as tf hello = tf.constant() sess = tf.Session() sess.run(hello)
结果如下:ModuleNotFoundError: No module named ‘tensorflow’
(二)加入运行路径

设置项目的编译器为python安装位置的python.exe,勾选导入所有的模块,显示如上图所示。再次运行出现同样的错误,查了一些资料应该是电脑的CPU太老了,我下载的tensorflow2.1.0版本不支持。
(三)安装2.0.0版本并测试
运行代码: pip unintall tensorflow
重新运行安装代码:pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
再次测试成功!

由于笔记本没有英伟达显卡,配置较低,只安装了CPU版本,后续使用有较好配置的电脑尝试安装GPU版本。确实CPU版本速度比较慢。