close

## OS: CentOS 7.2 (7.2.1511) (如果要跑 tensorflow, 建議作業系統使用 ubuntu, 若只跑 machine learning, 可以使用 CentOS)

## 無 GPU, 純 CPU 環境

## 一些標註使用 root 身份作業的指令可以用 sudo 代替


## 安裝 Anaconda 3 (考慮到不讓 user 亂裝東西, 使用 root 身份, path 裝到 /usr/anaconda3 下)

## 使用 ubuntu 的話原本就只能用 sudo, 使用 CentOS 的話, 可以先將某個 user 加入 wheel 這個群組裡, 讓該 user 可以使用 sudo 指令. 加完後需登出登入才會生效 (或直接再 su 一次也可以)

# usermod -aG wheel <username>

## 若之後要用 PyCharm 開發, 需先比對 PyCharm 所支援的 Python 版本, 再去對應 Anaconda 的版本, 或是直接在 Anaconda 裡裝較早版本的 python, 例如, conda install python=3.6, 原廠說明 link 如下:

## http://docs.anaconda.com/anaconda/user-guide/faq/#anaconda-faq-35

## 主要版本對應如右: Python 3.5 (Anaconda 4.2.0) or Python 3.6 (Anaconda 5.2.0)

## 接下來就可以 download Anaconda 所需的版本, 如果有要跑 tensorflow, 就也要去查所支援的 python 版本

## https://www.tensorflow.org/install/pip

## 這裡使用的方式, 採用下載最新版的 Anaconda with 最新版的 python, 再於虛擬環境建立 python 3.5 的環境, 用來配合 Tensorflow.

wget https://repo.anaconda.com/archive/Anaconda3-5.3.0-Linux-x86_64.sh

chmod +x Anaconda3-5.3.0-Linux-x86_64.sh

sudo bash Anaconda3-5.3.0-Linux-x86_64.sh

## 按 Enter 進入 License 授權說明

## 輸入 yes 同意 license terms

Do you approve the license terms? [yes|no]

>>> yes

## 輸入欲安裝的路徑

[/root/anaconda3] >>> /usr/anaconda3

## 輸入 yes 讓安裝程式在 root 的 .bashrc 裡增加 export PATH="/usr/anaconda3/bin:$PATH" 這筆記錄. 這裡先加進來沒關係, 不影響系統後端運作.

## 較新的版本會被詢問是否安裝 Microsoft VSCode, 這個就看個人寫 code 習慣了, 個人是選 no

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

>>> no


## 回到欲使用 tensorflow 的 user 身份, 依 Linux distribution 編輯 .bashrc 或 .profile, 修改 PATH
su - <ml_user_name>
vi ~/.bashrc
內容如下:
# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/usr/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/usr/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/usr/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/usr/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

## 離開編輯模式
. ~/.bashrc           ## 假設上述設定是寫在 .bashrc 裡

## 使用欲使用 tensorflow 的 user 身份安裝不同版本的 python
conda search --full-name python                        ## 先 search 看看有支援哪些版本
conda create -n tfuser120181027 python=3.5 anaconda    ## 建立 python 3.5 的環境, anaconda 是指 is the metapackage that includes all of the Python packages comprising the Anaconda distribution.
source activate tfuser120181027
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.11.0-cp35-cp35m-linux_x86_64.whl
[pip install pandas-datareader]                        ## 若會用到 pandas 讀入 data set, 那麼需要加裝這個
[pip list --format=columns]

# 測試 Tensorflow 是否裝成功
(tfuser120181027) [user1@ml1 Desktop]$ python
Python 3.5.5 |Anaconda, Inc.| (default, May 13 2018, 21:12:35)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
tf.estimator package not installed.
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello).decode())
Hello, TensorFlow!
>>> exit()

## 注意上方出現 tf.estimator package not installed. 的訊息. 這可能是因為套件安裝順序的關係, 重裝 pandas 後就不會再出現.
(tfuser120181027) [user1@ml1 Desktop]$ pip install --ignore-installed pandas
(tfuser120181027) [user1@ml1 Desktop]$ python
Python 3.5.5 |Anaconda, Inc.| (default, May 13 2018, 21:12:35)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello).decode())
Hello, TensorFlow!
>>> exit()
(tfuser120181027) [user1@ml1 Desktop]$

# 離開 tensorflow 虛擬環境
(tensorflow) [user1@localhost ~]$ source deactivate tensorflow

## 以 root 身份安裝 pycharm (需要圖型介面)
mkdir -p /root/Downloads/pycharm
cd /root/Downloads/pycharm
wget https://download.jetbrains.com/python/pycharm-community-2018.2.4.tar.gz
tar xfz pycharm-*.tar.gz -C /opt/
cd /opt/pycharm-*/bin
./pycharm.sh
## 第一次 start pycharm 會有以下幾個選項, 按照自己的習慣設定就可以了.
## 1. Import PyCharm settings (沒有之前的版本時, 選 Do not import settings 就可以了)
## 2. Select the user interface theme
## 3. Create Launch Script                       # 這裡勾選並保持預設值 /usr/local/bin/charm
## 4. Download and install additional plugins
## 5. 預設的 jvm 可使用的記憶體不夠大, 建議在首次 Welcome to PyCharm 畫面, 按下方的 Configure => Edit Custom VM Options, 調整值如下,
## Xms1536m
## Xmx1536m
## 然後儲存, 並且離開 pycharm
chmod o+x /usr/local/bin/charm    # 調整 pycharm 啟動 script 的權限, 讓欲使用 pycharm 的 user 也可以啟動 pycharm
## 改用欲使用 pycharm 的 user 登入, 前面的 1 ~ 5 項會再走一遍, 但第 3 項不用再勾選
[user1@ml1 Desktop]$ source activate tfuser120181027
(tfuser120181027) [user1@ml1 Desktop]$ nohup charm &

## 出現 Welcome to PyCharm 畫面, 點選 Create New Project
## 輸入專案路徑, 路徑最後一個是專案名稱, 展開下方的 Project Interpreter, 選 Existing interpreter, 點選旁邊的 ... 按紐 =>
## 出現 Add Python Interpreter 設定畫面, 左邊選 Conda Environment, 右邊點選旁邊的 ... 按紐, 展開樹狀圖, 找到 /home/<username>/.conda/envs/<conda_env_name>/bin/python => 選 OK => 選 Create
## 可以正式開始 coding 囉! ^_^

######################################################################

This document was created by 陳兆康 (Chao-Kang Chen) (國泰世華銀行 DBA)

arrow
arrow

    kangkang0705 發表在 痞客邦 留言(0) 人氣()