Linux mint環(huán)境搭建keras深度學習開發(fā)環(huán)境

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

介紹下過程:

安裝Anaconda

1.下載

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

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

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

3.在安裝過程中會顯示配置路徑

Prefix=/home/he/anaconda3/

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

5.在終端輸入$sudo vim /etc/profile,打開profile文件

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

7.重啟Linux

8.打開終端,輸入python,出現如下界面,表明設置成功。

還可以用conda info 來查詢安裝信息

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

如果你還有什么包沒有安裝上,可以運行conda install ***? 來進行安裝(***代表包名稱),如果某個包版本不是最新的,運行conda update *** 就可以。

設置conda鏡像源

因為默認的conda安裝源在國外,安裝時會比較慢,建議改成國內鏡像源,這樣安裝其他包時會比較快。

終端中運行命令:

(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.打開終端

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

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

conda activate keras

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

conda install tensorflow

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

? ? ? ? ? ? import tensorflow as tf

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

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

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

正確的話,會輸出: Hello, TensorFlow!

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

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

conda install ipython

conda install jupyter

2.然后,進去Jupyter,直接輸入:

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

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

conda install scikit-learn

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

conda install keras

至此,深度學習,機器學習開發(fā)環(huán)境就已經安裝完畢了,可以通過命令

jupyter notebook

打開notebook進行開發(fā),輸入以下代碼,如果沒有報錯,就證明環(huán)境安裝成功了。

import keras

注意:改完anaconda安裝源,安裝其他包時報錯

我的報錯信息:

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

解決方案:

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

cp ~/.condarc{,.bak}

查看配置文件的內容

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、刪除部分內容

修改后配置文件的內容如下:

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

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

相關閱讀更多精彩內容

友情鏈接更多精彩內容