Mac Pycharm+anaconda+tensorflow环境搭建以及遇到的坑
环境:macOS 10.14
python系统自带2.7以及自己安装的3.7
安装anaconda
在官网下载,按照步骤操作即可,下载地址
安装Tensorflow
- 建立一个 conda 计算环境,命令行输入:
$ conda create -n tensorflow python=3.7
- **tensorflow环境
$ source activate tensorflow
- 安装
$ pip install tensorflow
- 终端测试:
$ python3 >>>import tensorflow >>>print(tf.__version__)
- 不使用的时候,关闭环境
(tensorflow)$ source deactivate
Pycharm配置
进入Pycharm,preference->project interpreter,选择anaconda3的envs的tensorflow下的Python3.7
坑1:
添加interpreter的时候出现:
Environment location is not empty.
是由于项目已经存在interpreter 了,删掉venv文件夹后就可以添加新的了。
坑2
上面都搞完了,导入tensorflow的时候,仍然显示:
No module named 'tensorflow'
重新回到interpreter的页面,发现下面没有显示tensorflow之类的包,这是找不到包的原因。
解决:发现是一个按钮没有选中:
选中后,下面出现了各种包:
运行测试程序:
import tensorflow as tf
if __name__ == '__main__':
hello = tf.constant('hello')
sess = tf.Session()
print(sess.run(hello))
成功!
可以开始使用了~