学习笔记-机器学习-搭建环境-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

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