安装过程参考的是https://blog.csdn.net/Xiao_Xue_Seng/article/details/83963566这篇博客!
1. 首先新建一个conda环境,命名为tensorflow:
conda create -n tensorflow python=3.6
但环境创建失败:
(操作时忘记截图了,但我和这篇博客中出现的问题一样https://blog.csdn.net/u011331430/article/details/102929912,该图片截取来自该篇博客)
解决方案参考该篇博客https://blog.csdn.net/hejp_123/article/details/98493042,但在执行命令conda config –add channels xxx时,出现了无法写入的问题,如下图所示:
于是到home文件夹下一探究竟。
在home下按ctrl+h,找到隐藏的文件.condarc,发现其属性为只读模式,于是打开终端,在终端中输入以下命令:
sudo chmod 666 /home/zyhk/.condarc
将.condarc文件改为可读可写文件,现在再执行添加镜像源的命令就能成功写入了。
接着,按照上文提到的参考博客,一步步操作:
# 添加镜像源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
# 设置搜索时显示通道地址:
conda config --set show_channel_urls yes
# 执行完上述命令后,会生成配置文件记录着我们对conda的配置
# 执行:
~/.condarc
# 编辑 .condarc
注释defalts(这个是解决问题的关键所在)
# 保存退出
# 最后,重新执行:
conda create -n tensorflow python=3.6
成功创建!如下图所示:
2. 激活环境:
source activate tensorflow
3. 安装tensorflow-gpu版本和keras(tensorflow与keras版本对应参考https://docs.floydhub.com/guides/environments/, 版本不对应运行程序时会报错):
conda install tensorflow-gpu keras
(安装错了的话,就执行conda uninstall xxx即可)
4. 测试
在终端中输入python,在python中输入:(没报错就成功了)
import tensorflow as tf
5、关闭激活环境
source deactivate tensorflow
另外,如果需要安装别的工具包,比如机器学习类的,在激活环境下,执行:
conda install numpy scipy scikit-learn scikit-image matplotlib
即可使用
由于我需要将tensorflow环境与pycharm相关联,由此,还行了以下操作:
pycharm中点击file→settings→progect Interpreter,通过设置python环境,可以将虚拟环境中的tensorflow导入至pycharm中。如下图所示:
参考博客:
https://blog.csdn.net/Xiao_Xue_Seng/article/details/83963566
https://blog.csdn.net/u011331430/article/details/102929912
https://blog.csdn.net/hejp_123/article/details/98493042
https://zhidao.baidu.com/question/873477129217973812.html
https://blog.csdn.net/qq_41621362/article/details/96021715
https://blog.csdn.net/leijieZhang/article/details/54955980
https://blog.51cto.com/11970781/2132327