Linux mint環(huán)境搭建keras深度學(xué)習(xí)開(kāi)發(fā)環(huán)境

搭建深度學(xué)習(xí)開(kāi)發(fā)環(huán)境,建議還是使用anaconda比較容易些,本人試圖直接在python3.7下安裝tensorflow和keras失敗了,后來(lái)還是用anaconda搭建成功了。

介紹下過(guò)程:

安裝Anaconda

1.下載

下載地址為:https://www.anaconda.com/download/#linux

2.安裝anaconda,執(zhí)行命令:

bash ~/下載/Anaconda3-2019.07-Linux-x86_64.sh

3.在安裝過(guò)程中會(huì)顯示配置路徑

Prefix=/home/he/anaconda3/

4.安裝完之后,運(yùn)行python,仍是系統(tǒng)自帶的python信息,需自己設(shè)置下環(huán)境變量

5.在終端輸入$sudo vim /etc/profile,打開(kāi)profile文件

6.在文件末尾添加一行:export PATH=/home/he/anaconda3/bin:$PATH,其中,將“/home/he/anaconda2/bin”替換為實(shí)際的安裝路徑,保存。

7.重啟Linux

8.打開(kāi)終端,輸入python,出現(xiàn)如下界面,表明設(shè)置成功。

還可以用conda info 來(lái)查詢安裝信息

輸入conda list 可以查詢你現(xiàn)在安裝了哪些庫(kù),常用的python, numpy, scipy名列其中。

如果你還有什么包沒(méi)有安裝上,可以運(yùn)行conda install ***? 來(lái)進(jìn)行安裝(***代表包名稱),如果某個(gè)包版本不是最新的,運(yùn)行conda update *** 就可以。

設(shè)置conda鏡像源

因?yàn)槟J(rèn)的conda安裝源在國(guó)外,安裝時(shí)會(huì)比較慢,建議改成國(guó)內(nèi)鏡像源,這樣安裝其他包時(shí)會(huì)比較快。

終端中運(yùn)行命令:

(1)清華源(TUNA)

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 --setshow_channel_urls yes

(2)中科大源(USTC)

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/

conda config --setshow_channel_urls yes

安裝keras


先創(chuàng)建虛擬環(huán)境并安裝tensorflow

1.打開(kāi)終端

2.創(chuàng)建一個(gè)叫做keras的conda環(huán)境并激活

conda create -n keras python=3.6(我們使用Python3.6會(huì)更穩(wěn)定些)

conda activate keras

3.安裝tensorflow,輸入以下命令:

conda install tensorflow

4.至此,我們已經(jīng)安裝好了TensorFlow。接下來(lái)可以測(cè)試驗(yàn)證下是否可以使用。在命令行輸入:Python,進(jìn)入Python編程環(huán)境。 然后輸入:

? ? ? ? ? ? import tensorflow as tf

? ? ? ? ? ? hello = tf.constant('Hello, TensorFlow!')

? ? ? ? ? ? sess = tf.Session()

? ? ? ? ? ? print(sess.run(hello))

正確的話,會(huì)輸出: Hello, TensorFlow!

在虛擬環(huán)境中安裝TensorFlow、Keras

1.首先,進(jìn)入keras環(huán)境,安裝ipython和jupyter。命令如下:

conda install ipython

conda install jupyter

2.然后,進(jìn)去Jupyter,直接輸入:

jupyter notebook (等待一下就會(huì)彈出瀏覽器,進(jìn)入Jupyter)

3.安裝scikit-learn,執(zhí)行命令:

conda install scikit-learn

4.安裝Keras,執(zhí)行命令:

conda install keras

至此,深度學(xué)習(xí),機(jī)器學(xué)習(xí)開(kāi)發(fā)環(huán)境就已經(jīng)安裝完畢了,可以通過(guò)命令

jupyter notebook

打開(kāi)notebook進(jìn)行開(kāi)發(fā),輸入以下代碼,如果沒(méi)有報(bào)錯(cuò),就證明環(huán)境安裝成功了。

import keras

注意:改完anaconda安裝源,安裝其他包時(shí)報(bào)錯(cuò)

我的報(bào)錯(cuò)信息:

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/noarch/current_repodata.json>

解決方案:

1、創(chuàng)建channels配置文件的備份

cp ~/.condarc{,.bak}

查看配置文件的內(nèi)容

cat ~/.condarc.bak

channels:

? - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

? - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

? - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

? - https://nanomirrors.tuna.tsinghua.edu.cn/anaconda/cloud

? - defaults

? - https://nanomirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda

? - https://nanomirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/conda

? - bioconda

? - r

? - conda-forge

show_channel_urls: true

2、刪除部分內(nèi)容

修改后配置文件的內(nèi)容如下:

vim ~/.condarc

channels:

? - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

? - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

? - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

show_channel_urls: true

3、還不行就把配置文件中https改為http

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容