1. 程式人生 > >CentOS伺服器搭建anaconda3+tensorflow環境

CentOS伺服器搭建anaconda3+tensorflow環境

  之前用自己的電腦跑程式,效果不是很好,老師分配了伺服器結點,所以就在伺服器上配置了一遍。作為小白,對Linux命令列並不是很熟,踩了不少坑,現在配置好了,記錄一下過程。

一、安裝Anaconda3

直接從官網下載非常慢,甚至連線不上,所以找了清華的映象https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/,我選擇了anaconda3-4.2.0-Linux-x86_64.sh.

執行wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Linux-x86_64.sh

下載完後會出現如下圖的提示,告訴你儲存到了哪裡,如圖的Saving to:‘Anaconda3-4.2.0-Linux-x86_64.sh.2'

隨後安裝,執行命令:bash Anaconda3-4.2.0-Linux-x86_64.sh.2

然後一路回車就行

由於我的環境中沒有bzip2,所以第一次操作出現了問題,安裝一個就行

接著就要啟用環境,輸入export PATH=/root/anaconda3/bin:$PATH就好了。

二、安裝tensorflow

首先建立tensorflow的環境

輸入命令:conda create -n tensorflow

然後source activate tensorflow進入tensorflow環境

然後通過pip命令安裝tensorflow,仍然使用了清華映象https://mirrors.tuna.tsinghua.edu.cn/help/tensorflow/

找到合適的版本,我這裡是cpu,python3.5,linux系統

輸入命令:pip install --ignore-installed --upgrade https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/tensorflow-1.7.0-cp35-cp35m-linux_x86_64.whl

自己會裝好,然後測試一下

//輸入python進入,然後輸入一下程式碼
import tensorflow as tf
hello=tf.constant('hello')
sess=tf.Session()
print(sess.run(hello))

正常輸出則證明環境搭建好了。

輸入命令:source deactivate 退出tensorflow環境