Anaconda3下载 从Anaconda官网下载linux版本:https://www.anaconda.com/download/#linux
Anaconda3安装 将下载好的文件Anaconda3-5.0.1-Linux-x86_64.sh执行如下命令:
1 # bash Anaconda3-5 .0 .1-Linux-x86_64 .sh
安装过程中修改Anaconda3的安装路径为/opt/modules/anaconda3:
1 2 3 4 5 6 7 8 9 10 11 12 13 Do you accept the license terms? [yes|no]Please answer 'yes ' or 'no ':' >>> yes Anaconda3 will now be installed into this location: /root/anaconda3 - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below [/root/anaconda3] >>> /opt/modules/anaconda3 PREFIX=/opt/modules/anaconda3
等待安装完成提示信息,询问是否要将Anaconda3添加到PATH环境变量中,直接回车(选择no):
1 2 3 4 5 6 7 8 9 10 installation finished. Do you wish the installer to prepend the Anaconda3 install locationto PATH in your /root/.bashrc ? [yes|no ][no ] >>> You may wish to edit your .bashrc to prepend the Anaconda3 install location to PATH : export PATH =/opt/modules/anaconda3/bin :$PATH Thank you for installing Anaconda3!
手动将export PATH=/opt/modules/anaconda3/bin:$PATH添加到/etc/profile中, 最后source /etc/profile使环境变量生效:
Tensorflow安装 建立Tensorflow运行环境 Tensorflow目前Python3版本最高支持到Python3.5,所以选择Python 3.5, 只需要执行conda create -n tensorflow python=3.5指令:
1 2 3 4 5 6 7 8 ## Python 2.7 # conda create -n tensorflow python=2.7 ## Python 3.5 # conda create -n tensorflow python=3.5 ## Python 3.6 # conda create -n tensorflow python=3.6
在Anaconda3中创建Tensorflow虚拟环境:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Fetching package metadata ........... Solving package specifications: . Package plan for installation in environment /opt/modules/anaconda3/envs/tensorflow: The following NEW packages will be INSTALLED: ca-certificates: 2017.08 .26 -h1d4fec5_0 certifi: 2017.11 .5 -py35h9749603_0 libedit: 3.1 -heed3624_0 libffi: 3.2 .1 -hd88cf55_4 libgcc-ng: 7.2 .0 -h7cc24e2_2 libstdcxx-ng: 7.2 .0 -h7a57d05_2 ncurses: 6.0 -h9df7e31_2 openssl: 1.0 .2 m-h26d622b_1 pip: 9.0 .1 -py35h7e7da9d_4 python: 3.5 .4 -h417fded_24 readline: 7.0 -ha6073c6_4 setuptools: 36.5 .0 -py35ha8c1747_0 sqlite: 3.20 .1 -hb898158_2 tk: 8.6 .7 -hc745277_3 wheel: 0.30 .0 -py35hd3883cf_1 xz: 5.2 .3 -h55aa19d_2 zlib: 1.2 .11 -ha838bed_2 Proceed ([y]/n)? libffi-3.2 .1 -h 100 % |##################################################################| Time: 0 :00 :00 137.60 kB/s ncurses-6.0 -h9 100 % |##################################################################| Time: 0 :00 :01 622.10 kB/s openssl-1.0 .2 m 100 % |##################################################################| Time: 0 :00 :03 1.06 MB/s tk-8.6 .7 -hc745 100 % |##################################################################| Time: 0 :00 :02 1.13 MB/s xz-5.2 .3 -h55aa 100 % |##################################################################| Time: 0 :00 :00 1.28 MB/s zlib-1.2 .11 -ha 100 % |##################################################################| Time: 0 :00 :00 1.59 MB/s readline-7.0 -h 100 % |##################################################################| Time: 0 :00 :00 1.27 MB/s sqlite-3.20 .1 - 100 % |##################################################################| Time: 0 :00 :01 1.41 MB/s python-3.5 .4 -h 100 % |##################################################################| Time: 0 :00 :07 3.87 MB/s certifi-2017.1 100 % |##################################################################| Time: 0 :00 :00 6.01 MB/s setuptools-36. 100 % |##################################################################| Time: 0 :00 :00 6.55 MB/s wheel-0.30 .0 -p 100 % |##################################################################| Time: 0 :00 :00 6.82 MB/s pip-9.0 .1 -py35 100 % |##################################################################| Time: 0 :00 :00 6.78 MB/s # # To activate this environment, use: # > source activate tensorflow # # To deactivate an active environment, use: # > source deactivate #
为了简便也可以直接指定版本python=3.5, 且克隆anaconda所有的Python包:
1 conda create -n tensorflow python =3.5 anaconda
conda环境管理 列出所有的环境 创建一个指定Python版本且包含anaconda所有Python包的新环境 1 # conda create -n py36 python=3.6 anaconda
克隆一个环境 创建一个和root环境一样的副本:
1 conda create -n py36 --clone root
删除一个环境 在conda环境下安装tensorflow(pip安装方式) 激活conda环境(tensorflow)
1 # source activate tensorflow
根据tensorflow的版本设置环境变量(以CPU版本为例) Tensorflow的源码地址: https://github.com/tensorflow/tensorflow,如下三种环境Python2.7 , Python3.4, Python3.5,选择一种(Python3.5)运行:
1 2 3 4 5 6 (tensorflow)$ export TF_BINARY_URL=https:// ci.tensorflow.org/view/ tf-nightly/job/ tf-nightly-linux/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON2,label=cpu-slave/ lastSuccessfulBuild/artifact/ pip_test/whl/ tf_nightly-1 .head-cp27-none-linux_x86_64.whl (tensorflow)$ export TF_BINARY_URL=https:// ci.tensorflow.org/view/ tf-nightly/job/ tf-nightly-linux/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON3,label=cpu-slave/ lastSuccessfulBuild/artifact/ pip_test/whl/ tf_nightly-1 .head-cp34-cp34m-linux_x86_64.whl (tensorflow)$ export TF_BINARY_URL=https:// ci.tensorflow.org/view/ tf-nightly/job/ tf-nightly-linux/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON3.5,label=cpu-slave/ lastSuccessfulBuild/artifact/ pip_test/whl/ tf_nightly-1 .head-cp35-cp35m-linux_x86_64.whl
使用pip命令安装tensorflow 选择一种安装环境(Python 3):
1 2 3 4 5 # (tensorflow)# pip install --ignore-installed --upgrade $TF_BINARY_URL # (tensorflow)# pip install --ignore-installed --upgrade $TF_BINARY_URL
使用conda命令安装tensorflow Using conda参照如下网址: A community maintained conda package is available from conda-forge.https://github.com/conda-forge/tensorflow-feedstock
Only the CPU version of TensorFlow is available at the moment and can be installed in the conda environment for Python 2 or Python 3.
1 2 $ source activate tensorflow (tensorflow)#
Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:
1 (tensorflow )# conda install -c conda-forge tensorflow
参考资料 【1】https://blog.csdn.net/liuguangrong/article/details/78737419