linux-Anaconda+conda创建python-tensorflow虚拟环境

Anaconda 安装包可以到清华 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下载可选择之前的版本。或者https://www.anaconda.com/download/#linux官网下载地址,最新版本。
(https://repo.continuum.io/archive/index.html)这里也有下载地址,可以使用命令下载,如下

 wget https://repo.continuum.io/archive/Anaconda3-5.3.0-Linux-x86_64.sh
##这是python3的,可以去上面的链接里,找到适合自己系统python版本的,比如
#wget https://repo.continuum.io/archive/Anaconda2-5.3.0-Linux-x86_64.sh
#按照需求自己选

不添加镜像,或者添加清华镜像https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/好处是下载快(其实我感觉差不多速度)自行选择。清华镜像添加是执行下面几句

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

然后执行

 bash Anaconda2-5.1.0-Linux-x86_64.sh

Anaconda is partnered with Microsoft! Microsoft VSCode is a streamlined
code editor with support for development operations like debugging, task
running and version control.
To install Visual Studio Code, you will need:
  - Administrator Privileges
  - Internet connectivity

Visual Studio Code License: https://code.visualstudio.com/license

Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]

#让你安装VS,不安,输入no

然后我们接下来创建虚拟环境

# 创建一个名为S2P的环境,指定Python版本是2.7
conda create --name S2P python=2.7

#查看刚才创建的所有环境
conda list env(指的是哪些包)
conda info --envs(指的是创建环境的名称)

# activate激活S2P
source activate S2P
# 激活后,会发现terminal输入的地方多了S2P的字样,实际上,此时系统做的事情就是把默认环境从PATH中去除,再把当前2.7加入PATH


python --version
# 可以看到系统已经切换到了2.7的环境

# 如果想返回默认的python环境,运行

source deactivate S2P


# 删除刚才创建的环境S2P
conda remove --name S2P --all

接下来在虚拟环境中安装tensorflow

 anaconda search -t conda tensorflow #查看版本和资源

然后决定你想要下载哪个版本

naconda show cjj3779/tensorflow-gpu
Using Anaconda API: https://api.anaconda.org
Name:    tensorflow-gpu
Summary: TensorFlow helps the tensors flow
Access:  public
Package Types:  conda
Versions:
   + 1.4.0

To install this package with conda run:
     conda install --channel https://conda.anaconda.org/cjj3779 tensorflow-gpu

根据提示,我们可以执行

 conda install --channel https://conda.anaconda.org/cjj3779 tensorflow-gpu

或者
(可以查看这个网站,下载比较受欢迎的tensorflow-gpu版本)[https://anaconda.org/search?q=tensorflow-gpu]

当然,还可以选择清华的镜像站,但是有时候会不稳定,不显示你想要版本的.whl文件

https://mirrors.tuna.tsinghua.edu.cn/help/tensorflow/
#这里有各种资源,可以直接下在后缀名为.whl的tensorflow版本

那么还有更好的方法,请移步与pypi,搜索tensorflow-gpu,找到你想要的版本

https://pypi.org/
import tensorflow as tf
tf.__version__
tf.__path__

执行上面两句话验证tensorflow,出现版本号就可以了

可能出现的问题!command not found: conda
解决方案:export PATH=~/anaconda3/bin:$PATH

猜你喜欢

转载自blog.csdn.net/CSS360/article/details/90107875