当前位置: 移动技术网 > IT编程>脚本编程>Python > Ubuntu 远程 Jupyter 配置

Ubuntu 远程 Jupyter 配置

2019年04月09日  | 移动技术网IT编程  | 我要评论

诺基亚gzt650,樱桃qvod,梅花币

ubuntu 远程 jupyter 配置

每次上课都要重新部署环境,最近看到阿里云的大学生优惠活动,就着手了一台云服务器,于是就把环境部署在上面了。

环境:阿里云 ubuntu 16.04 64位

新建普通用户

su root                           # 切换到管理员用户
useradd -r -m -s /bin/bash 新用户名     # 新建用户
passwd 新用户名                    # 设置新用户密码
su 新用户名                       # 切换使用新用户

云主机添加安全组

云服务器默认只开启了几个端口,我们要手动增加开放的端口,jupyter 默认使用的是 8888 端口,具体操作看服务器提供商的文档。

安装、配置 anaconda

为了方便下载、更新我们使用。

cd ~
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/anaconda3-5.3.0-linux-x86_64.sh
sudo chmod 776 anaconda3-5.3.0-linux-x86_64.sh
sudo ./anaconda3-5.3.0-linux-x86_64.sh

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 --version

如果报错需配置环境变量,编辑 /etc/environment,添加 :/home/***/anaconda3/bin

配置 jupyter notebook 远程访问

  • 使用命令生成配置文件

    jupyter notebook --generate-config

  • 利用 ipython 生成密钥

    in [1]: from notebook.auth import passwd
    in [2]: passwd()
    enter password:
    verify password:
    out[2]: 'sha1:********************************'
  • 编辑生成的配置文件 ~\.jupyter/jupyter_notebook_config.py

    # 限定可以访问的ip
    c.notebookapp.ip= '*'
    # 粘贴上面生成的密钥
    c.notebookapp.password = u'sha1:**************************************'
    c.notebookapp.open_browser = false
    c.notebookapp.port = 8888
    
    # 配置默认的工作目录
    c.notebookapp.notebook_dir = '/home/dev'

启动和关闭 jupyter

  • 启动

    jupyter notebook &

  • 关闭

    ps -aux         # 查看进程的 pid
    sudo kill pid

方便开发的 jupyter 配置

pip 使用清华镜像

pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

小提示:安装 anaconda 时一定要勾选修改 .bashrc,自己配很麻烦,容易和系统自带的 python2.7 冲突。

使用代码提示

  • 安装 nbextensions
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
  • 安装 nbextensions_configurator
pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
  • 重启jupyter,在弹出的主页面里,能看到增加了一个nbextensions标签页,在这个页面里,勾选 hinterland 即启用了代码自动补全

美化 jupyter

pip install jupyterthemes
jt -t grade3 -fs 12 -altp -tfs 12 -nfs 12 -cellw 88% -t

参考:

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网