Centos7-Python3-Tensorflow-CPU/GPU

建议不要使用Centos6.5以及更低的系统安装Tensorflow GPU版本,可以尝试下CPU版的,具体情况可以参见:https://blog.csdn.net/edward_zcl/article/details/88585463
反正我是放弃Centos6.5系统下安装GPU版的Tensorflow了,Centos6.5感觉是个坎。。
Ubuntu用户请参见https://blog.csdn.net/edward_zcl/article/details/88636903
以下主要讲解Centos7下面安装Tensorflow,转载自:https://blog.csdn.net/liuguangrong/article/details/78737419

CentOS7下安装Anaconda3和Tensorflow

Anaconda3下载

从Anaconda官网下载linux版本:https://www.anaconda.com/download/#linux

Anaconda3安装

将下载好的文件Anaconda3-5.0.1-Linux-x86_64.sh执行如下命令:

# bash Anaconda3-5.0.1-Linux-x86_64.sh
  
  

    安装过程中修改Anaconda3的安装路径为/opt/modules/anaconda3:

    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):

      installation finished.
      Do you wish the installer to prepend the Anaconda3 install location
      to 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使环境变量生效:

        # source /etc/profile
          
          

          Tensorflow安装

          建立Tensorflow运行环境

          Tensorflow目前Python3版本最高支持到Python3.5,所以选择Python 3.5, 只需要执行conda create -n tensorflow python=3.5指令:

          ## Python 2.7
          # conda create -n tensorflow python=2.7  
          
          ## Python 3.4  
          # conda create -n tensorflow python=3.4  
          
          ## Python 3.5  
          # conda create -n tensorflow python=3.5
            
            

            在Anaconda3中创建Tensorflow虚拟环境:

            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.2m-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.2m 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包:

              conda create -n tensorflow python=3.5 anaconda
                
                

                conda环境管理

                列出所有的环境

                # conda info --envs
                  
                  

                  创建一个指定Python版本且包含anaconda所有Python包的新环境

                  # conda create -n py36 python=3.6 anaconda
                    
                    

                    克隆一个环境

                    创建一个和root环境一样的副本:

                    conda create -n py36 --clone root
                      
                      

                      删除一个环境

                      # conda remove -n py36 --all
                        
                        

                        在conda环境下安装tensorflow(pip安装方式)

                        激活conda环境(tensorflow)

                        # source activate tensorflow
                          
                          

                          根据tensorflow的版本设置环境变量(以CPU版本为例)

                          Tensorflow的源码地址: https://github.com/tensorflow/tensorflow,如下三种环境Python2.7, Python3.4, Python3.5,选择一种(Python3.5)运行:

                          ## Linux 64-bit, CPU only, Python 2.7 
                          (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 
                          ## Linux 64-bit, CPU only, Python 3.4 
                          (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
                          ## Linux 64-bit, CPU only, Python 3.5 
                          (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.

                          使用pip命令安装tensorflow

                          选择一种安装环境(Python 3):

                          ## Python 2 
                          (tensorflow)# pip install --ignore-installed --upgrade $TF_BINARY_URL 
                          
                          ## Python 3 
                          (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.

                            $ source activate tensorflow 
                            (tensorflow)# 
                              
                              

                              Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:

                              (tensorflow)# conda install -c conda-forge tensorflow
                                
                                

                                参考资料

                                【1】https://docs.anaconda.com/anaconda/faq#how-do-i-get-the-latest-anaconda-with-python-3-5
                                【2】http://blog.csdn.net/goodshot/article/details/62046214
                                【3】http://blog.csdn.net/nxcxl88/article/details/52704877?locationNum=13

                                猜你喜欢

                                转载自blog.csdn.net/edward_zcl/article/details/85008155