jupyter

jupyter lab 的安装与配置

参考

安装

pip install jupyterlab

添加配置

jupyter lab --generate-config

设置密码

jupyter lab password

启动

1
2
3
4
5
6
jupyter lab --ip 0.0.0.0 --port 11111 --no-browser --notebook-dir='/home/zzm'
--ip=0.0.0.0 监听所有ip,允许其他电脑访问
--no-brower 不启动本地浏览器
--notebook-dir 指定根目录

jupyter lab --ip :: --port 11111 --no-browser --notebook-dir='/home/zzm' 设置ipv6访问

问题

jupyter UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 4
解决:
修改系统语言变量为英文

1
2
3
sudo vim /etc/default/locale   #用 vim 来修改环境的语言配置
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"

修改完成,查看系统语言
locale

jupyter中添加conda环境

安装完Anaconda利用conda创建了虚拟环境,但是启动jupyter notebook之后却找不到虚拟环境。
实际上是由于在虚拟环境下缺少kernel.json文件,解决方法如下:

  • 首先安装ipykernel:conda install ipykernel
  • 在虚拟环境下创建kernel文件:conda install -n 环境名称 ipykernel
  • 激活conda环境: source activate 环境名称
  • 将环境写入notebook的kernel中
    python -m ipykernel install --user --name 环境名称 --display-name "Python (环境名称)"
  • 打开notebook服务器:jupyter notebook
    浏览器打开对应地址,新建python,就会有对应的环境提示了
  • 如果经常需要用jupyter notebook,那么最好在创建虚拟环境的时候便安装好ipykernel,
    命令:conda create -n 环境名称 python=3.7 ipykernel
  • 删除kernel环境:
    jupyter kernelspec remove 环境名称
  • 查看kernel: jupyter kernelspec list

进入conda环境中启动jupyter
通过直接启动无法显示
可以添加conda kernel

1
2
3
4
conda create -n py3 python=3 # 创建一个python3的环境,名为py3
source activate py3 # 激活py3环境
conda install ipykernel # 安装ipykernel模块
python -m ipykernel install --user --name py3 --display-name "py3" # 进行配置

Contents
  1. 1. 安装
  2. 2. 添加配置
  3. 3. 设置密码
  4. 4. 启动
  5. 5. 问题
  6. 6. jupyter中添加conda环境
|