jupyter lab 安装与远程使用(并配置C/C++ kernel)

本教程基于Centos 8 部署,先用sudo adduser xxx 创建一个新用户,jupyter在此账号下运行。

一、安装anaconda

1、在Linux服务器是新建议一个用户xxx,并切换到相应的用户  sudo xxx;

2、在/home/xxx/下载安装脚本 

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

Anaconda3-2020.07-Linux-x86_64.sh 可以在清华镜像站找最新的版本替换,清华大学开源软件镜像站https://mirrors.tuna.tsinghua.edu.cn。

3、运行安装向导

bash Anaconda3-2019.10-Linux-x86_64.sh

 安装完成后reboot

3、重启完成后确认是否安装成功

conda --version

二、配置jupyter lab

  1. 进入python命令行模式,输入以下命令:

    from notebook.auth import passwd
    passwd()

    输入方便你记的密码,连续输;两次..输完密码后,会输出一个字符串,形如: ’sha1:9e7a5c5e0a29:8cbdvsv2344d141c92beab1c5bc6e9avsdvdsvsv’将其保存下来, 完成以上操作后,通过exit()推出ipython环境

  2. 进入到安装目录:cd /home/xxx/anaconda3/etc/jupyter, 执行 :

    jupyter lab --generate-config

    命令会产生配置文件:/home/xxx/.jupyter/jupyter_notebook_config.py

  3. 编辑配置文件
    vi /home/xxx/.jupyter/jupyter_notebook_config.py 修改相关内容如下:

     c.NotebookApp.ip = '*' # 允许访问此服务器的 IP,星号表示任意 IP
     c.NotebookApp.password = u'sha1:xxx:xxx' # 之前生成的密码 hash 字串
     c.NotebookApp.open_browser = False # 运行时不打开本机浏览器
     c.NotebookApp.port = 8888 # 使用的端口,随意设置
     c.NotebookApp.enable_mathjax = True # 启用 MathJax
     c.NotebookApp.allow_remote_access = True #允许远程访问
     c.NotebookApp.notebook_dir = '/home/xxxx/notebook' 默认打开的工作目录
    
  4. su root 打开防火墙
    firewall-cmd --zone=public --add-port=8888/tcp --permanent
    firewall-cmd --reload
    firewall-cmd --query-port=8888/tcp
     
  5. 启动服务
    #前台运行模式(命令行窗口不能关闭)
    jupyter lab
    #后台运行模式
    nohup jupyter lab &
    远程通过浏览器就可以访问jupyter lab了。
  6. jupyter lab 安装插件
  • 安装 node.js
    conda install nodejs
  • 打开 Extension Manager (默认是关闭的)
    jupyter lab 安装与远程使用(并配置C/C++ kernel)_第1张图片

三、给jupyter lab 安装C++ kernel

  1. 安装C++ kernel(xeus-cling)
    创建新的虚拟环境,命名为cling,或者你喜欢的其他名称
    conda create -n cling
  2. 切换到新创建的虚拟环境
    conda activate cling

     

  3. 给新环境安装jupyter lab

    conda install jupyterlab

     

  4. 使用conda-forge镜像channel安装xeus-cling

    conda install xeus-cling -c conda-forge

     

  5. 检查是否成功安装了kernel
     

    jupyter kernelspec list

     

  6. 正确安装,会显示以下四个kernel:

    python3 /anaconda3/envs/cling/share/jupyter/kernels/python3
    xcpp11 /anaconda3/envs/cling/share/jupyter/kernels/xcpp11
    xcpp14 /anaconda3/envs/cling/share/jupyter/kernels/xcpp14
    xcpp17 /anaconda3/envs/cling/share/jupyter/kernels/xcpp17

     

四 、给jupyter lab 安装C kernel(jupyter-c-kernel)

  1. 安装步骤跟安装(C++ kernel)类似,直接按照以下步骤安装
    #如果没有安装gcc需要预先安装,否则程序无法运行
    $yum install gcc
    
    conda activate cling 
    pip install jupyter-c-kernel
    install_c_kernel --user
    jupyter kernelspec list
      c          /home/heaven/.local/share/jupyter/kernels/c
      python3    /home/heaven/anaconda3/envs/cling/share/jupyter/kernels/python3
      xcpp11     /home/heaven/anaconda3/envs/cling/share/jupyter/kernels/xcpp11
      xcpp14     /home/heaven/anaconda3/envs/cling/share/jupyter/kernels/xcpp14
      xcpp17     /home/heaven/anaconda3/envs/cling/share/jupyter/kernels/xcpp17

     

五、运行jupyter lab

conda activate cling
#前台运行模式(命令行窗口不能关闭)
jupyter lab
#后台运行模式
nohup jupyter lab &

jupyter lab 安装与远程使用(并配置C/C++ kernel)_第2张图片

参考文章:
https://blog.csdn.net/weixin_37543731/article/details/99254107

你可能感兴趣的:(Jupyter,Notebook)