美文网首页
Ubuntu anaconda 配置 Jupyter Lab

Ubuntu anaconda 配置 Jupyter Lab

作者: 谖瓞 | 来源:发表于2020-04-12 12:05 被阅读0次

    Ubuntu 下安装并配置 Jupyter Lab。

    基础部分

    安装 Jupyter Lab

    conda install -c conda-forge jupyterlab
    

    基础配置

    获取服务密码

    进入 ipython 中:

    ipython3
    

    在 ipython 中输入:

    from notebook.auth import passwd
    passwd()
    

    会输出一串密码,(图中密码仅作为示例,请勿直接复制使用)需要保存下来,等下配置会用到。


    生成服务密码

    生成配置文件

    输入以下命令生成配置文件:

    jupyter lab --generate-config
    

    使用 vim 编辑 Jupyter lab 配置文件:

    vim ~/.jupyter/jupyter_notebook_config.py
    

    修改以下内容:

    # 允许远程登录
    c.NotebookApp.allow_remote_access = True
    # 允许 root 启动
    c.NotebookApp.allow_root = True
    # 允许任意 ip 访问
    c.NotebookApp.ip = '*'
    # 设置默认文件夹位置,需要在运行前事先创建好文件夹
    c.NotebookApp.notebook_dir = '/home/notebook'
    # 默认不开启浏览器
    c.NotebookApp.open_browser = False
    # 配置服务密码
    c.NotebookApp.password = u'输入上面生成的密码'
    # 配置 Jupyter Lab 端口
    c.NotebookApp.port = 8888
    

    运行 Jupyter Lab

    创建一个名为 “Jupyter” 新的 screen:

    screen -S 'Jupyter'
    

    在新的 screen 内运行:

    jupyter lab
    

    此时按 Ctrl + A + D即可离开这个 screen,且不关闭 Jupyter Lab。

    增强部分

    准备工作

    添加 ppa 源

    执行以下命令:

    sudo apt-get install software-properties-common
    sudo add-apt-repository ppa:chronitis/jupyter
    

    安装 yarn

    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
    sudo apt-get update && sudo apt-get install yarn
    

    安装 nodejs

    conda install nodejs
    

    换源

    yarn 换淘宝源

    yarn config set registry 'https://registry.npm.taobao.org'
    

    npm 换淘宝源

    npm config set registry 'https://registry.npm.taobao.org'
    

    配置内核

    创建虚拟环境

    首先在 conda 下创建虚拟环境:

    # X.X 可填 2.7,3.6 等
    conda create -n your_env_name python=X.X
    

    安装内核

    因为我使用了 zsh,所以需要初始化一下:

    conda init zsh
    

    然后输入以下命令即可激活环境:

    conda activate your_env_name
    

    在环境中安装所需要的包:

    conda install -n your_env_name conda-forge jupyterlab
    

    再执行以下命令添加内核:

    python -m ipykernel install --name display_name
    

    最后在环境中执行即可退出当前环境:

    conda deactivate
    

    相关文章

      网友评论

          本文标题:Ubuntu anaconda 配置 Jupyter Lab

          本文链接:https://www.haomeiwen.com/subject/blnhwqtx.html