win10安裝mxnet-gpu以及在jupyter notebook中使用虛擬環境

win10安裝mxnet-gpu以及在jupyter notebook中使用虛擬環境

爲了學習動手學習深度學習的課程,需要安裝mxnet-gpu,遇到了以下幾個問題,查了很多博客,但由於某些博客寫得不大清楚浪費了很多時間,在此記錄一下自己已經實現,能確保成功的方法

首先說一下遇到的問題:

1.conda install慢

2.mxnet-gpu目前不支持python3.7

3.jupyter notebook無法使用虛擬環境

解決方案如下:

1.conda install慢

使用清華的源,寫博客時間是2020年1月30日,此時清華的源是可以使用的(之前關閉過,後來又恢復了),使用方法打開cmd,輸入以下代碼:

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 --set show_channel_urls yes

第三行代碼是用來生成.condarc文件的,該文件在c盤用戶目錄下,找到該文件後,將以下內容複製粘貼覆蓋源文件,以使得conda install下載包的速度變快

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

2.mxnet-gpu目前不支持python3.7

創建一個虛擬環境,在虛擬環境中使用python3.6即可。
我是直接用的《動手學習深度學習》中給的enviroment.yml文件來創建的
創建方法:進入到enviroment.yml的路徑後
conda env create -f environment.yml
enviroment.yml文件內容如下,創建記事本,複製粘貼一下內容進去後改後綴爲yml即可

name: gluon
dependencies:
- python=3.6
- pip:
  - mxnet-cu100     
  - d2lzh==0.8.11
  - jupyter==1.0.0
  - matplotlib==2.2.2
  - pandas==0.23.4

激活虛擬環境

conda activate gluon

不知道是不是我哪裏操作不對,我裝好的虛擬環境裏並沒有mxnet的包,所以在激活環境的目錄裏輸入

(gluon)你的路徑> conda install mxnet-gpu

即可完成mxnet-gpu的安裝,我沒有裝cuda,這一步我看下載裏面會自動下載cuda-toolkit,所以我猜測並不需要手動裝cuda。

3.jupyter notebook無法使用虛擬環境

這一步我沒有驗證過,只是確保這種能用,但其中可能會有冗餘步驟,歡迎大神指出
在剛剛激活的環境下

(gluon)你的路徑> conda install ipykernel

再開一個cmd,直接寫

你的路徑> conda install ipykernel

在激活環境下

(gluon)你的路徑> python -m ipykernel install --name gluon

開啓jupyter notebook

(gluon)你的路徑> jupyter notebook

在右側new下可以看到有Python3和剛剛創建的gluon兩個環境,選擇gluon就可以了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章