最近要在mac上装一下tensorflow跑实验,尝试了两种方法,在这里记录一下。
方法一:根据官网的说明,安装失败…
主要就是参照了官网的步骤,参见安装步骤,我是在进行下载tensorflow代码的步骤出现了问题:
git clone https://github.com/tensorflow/tensorflow.git
多次下载都出现了报错:
error: RPC failed; curl 18 transfer closed with outstanding read data remain
查了下大概是内存或者网络的问题,试了一下午各种解决方案未果,放弃…
方法二:参照了TensorFlowNews博客中介绍的方法,我选择了使用virtualenv安装的方式,步骤如下:
1.打开终端,用pip安装virtualenv
sudo pip install --upgrade virtualenv
2.创建虚拟环境
virtualenv --system-site-packages targetDirectory # for Python 2.7
virtualenv --system-site-packages -p python3 targetDirectory # for Python 3.n
注:targetDirectory用tensorflow的安装路径替换
3.激活tensorflow环境
source tensorflow/bin/activate # If using bash, sh, ksh, or zsh
source tensorflow/bin/activate.csh # If using csh or tcsh
4.安装tensorflow及其依赖项
pip install --upgrade tensorflow # for Python 2.7
pip3 install --upgrade tensorflow # for Python 3.n
pip install keras -U --pre #for keras
5.验证安装
执行python命令
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
成功打印则安装成功
6.退出tensorflow环境
deactivate
7.卸载tensorflow,移除目录即可
扫描二维码关注公众号,回复:
9424736 查看本文章
rm -r /tensorflow