1、先安装anaconda3 最好对应Python3.6
清华镜像
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
官网镜像
https://repo.anaconda.com/archive/
PS:
-
anaconda 5.2.0 对应python 3.6;
-
如果出现anaconda-navigator 闪退的情况,是因为版本问题,更新即可。(版本升级)
升级navigator,执行conda update anaconda-navigator
重置navigator,执行anaconda-navigator --reset
升级客户端,执行conda update anaconda-client
升级安装依赖包,执行conda update -f anaconda-client
(楼主尝试:前两步即可) -
环境变量配置
修改bash_profile
vim ~/.bash_profile
增加 export PATH="/Users/nick(你自己的安装路径)/anaconda3/bin:$PATH"
保存文件后,文件生效
source $HOME/.bash_profile -
如果出现每次打开 jupyter notebook 都需要重新激活环境变量的话,是因为 ‘.zshrc’ 文件中并没有定义任务环境变量。 在~/.zshrc文件最后,增加一行:
source ~/.bash_profile
2、Tensorflow 配置
- 创造tensorflow的环境
conda create -n tensorflow pip python=3.6 - 激活环境
conda activate tensorflow - 在该环境中使用pip安装tensorflow
pip install tensorflow
(PS :这里如果出现 Read timed out,原因为下载超时,可以改用清华镜像进行安装,速度会快很多
pip --default-timeout=100 install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.4.0
注意:默认下的是2.x 版本,2.x 和 1.x API有很大的差异,常写代码还是1.x)
(如果装错版本需要卸载的话
pip show tensorflow
pip uninstall tensorflow)
- 查看是否安装完成
仍然在Tensorflow 的环境中进入 Python3
import tensorflow as tf
3、在Jupyter notebook中使用tensorflow
值得注意的是,安装好tensorflow后,在全局的Jupyter notebook中仍然无法使用tensorflow,会出现没有tensorflow这个包的错误。
那么我们需要在tensorflow环境中安装 jupyter才可以
source activate tensorflow
conda install ipython
conda install jupyter
安装完成后在 tensorflow 的环境中输入 jupyter notebook
就可以正常使用了
官方教程
tf1.x的入门 https://github.com/tensorflow/docs/tree/master/site/en/r1/tutorials
2.x的教程 https://www.tensorflow.org/tutorials (需要翻墙)