學習筆記-機器學習-搭建環境-7:安裝Anaconda和Jupyter Notebook(CentOS和Ubuntu)

一、安裝Docker

參考:https://blog.csdn.net/RambleMY/article/details/84786799

二、安裝Anaconda

創建並運行容器:

$ docker run --runtime=nvidia -it -p 9999:8888 -v /root/myDocker:/share --privileged=true --name my-DL [image] /bin/bash

2.1 Centos上

以下操作在容器內進行

$ yum -y install wget
$ yum -y install setup
$ yum -y install perl
$ yum -y install bzip2

$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.1.0-Linux-x86_64.sh
$ bash Anaconda3-5.1.0-Linux-x86_64.sh

# 添加環境變量
$ vi ~/.bashrc
# 在最後添加:
export PATH="~/anaconda3/bin:$PATH"

# 環境變量生效
$ source ~/.bashrc

# 驗證是否安裝成功
$ conda -V

# 更新
$ conda update conda
$ conda upgrade --all

2.2 Ubuntu上

從官網上下載安裝包

運行安裝包

sh Anaconda3-5.3.1-Linux-x86_64.sh

參考Centos安裝Anaconda添加環境變量

 

2.3 修改爲國內鏡像源

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

# 刪除添加的鏡像源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

# 查看anaconda的配置信息
conda config --show

 

2.4 刪除anaconda

總會用到的。。

# 刪除
rm -rf /root/Anaconda3

 

 

三、安裝Jupyter Notebook

# 安裝jupyter notebook
$ conda install jupyter notebook

設置遠程訪問jupyter

# 生成jupyter配置文件
$ jupyter notebook --generate-config --allow-root
>> Writing default config to: /root/.jupyter/jupyter_notebook_config.py

# 使用ipython生成密碼
$ python //進入python交互模式
$ from notebook.auth import passwd
$ passwd()

>> Enter password: 
>> Verify password: 
>> 'sha1:dcdafd5a2d99:46835f3a56e8789cd9e771e12a4423afc8d0cadc'

# 修改配置文件
$ vi ~/.jupyter/jupyter_notebook_config.py

c.NotebookApp.allow_remote_access = True
c.NotebookApp.ip='*' # 設置所有ip皆可訪問
c.NotebookApp.password = u'sha1:上面生成的哈希值' # 
c.NotebookApp.open_browser = False # 禁止自動打開瀏覽器
c.NotebookApp.port = 8888 #指定一個端口

# 啓動jupyter notebooke
$ jupyter notebook --allow-root

因爲我們在創建容器的時候將宿主機的9999端口映射到了容器的8888端口,既jupyter notebook綁定的端口,因此我們通過訪問:[服務器ip]:9999遠程訪問jupyter notebook。

 

 

參考

https://blog.csdn.net/RambleMY/article/details/84452307

https://blog.csdn.net/u011552182/article/details/80054899

https://www.cnblogs.com/kevingrace/p/9453987.html

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