Linux下安装Jupyter并配置多个ipykernel

安装Jupyter

pip3 install jupyter notebook

或者:

pip install -i https://pypi.douban.com/simple jupyter

生成配置文件

jupyter notebook --generate-config

输出结果:
                Writing default config to: /root/.jupyter/jupyter_notebook_config.py

生成固定密码

打开Python3解释器执行以下代码:

from notebook.auth import passwd
passwd() 

Python3解释器:

>>> from notebook.auth import passwd
>>> passwd()
Enter password: 
Verify password: 
'argon2:$argon2id$v=19$m=10240,t=10,p=8$qw8yRM9/eAZs9u5DglQj4g$GIkKx6mVzmm5zO0TyNXDZA'

修改配置文件

vim /root/.jupyter/jupyter_notebook_config.py

复制上一步中的产生的加密密码,修改password:

c.NotebookApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$qw8yRM9/eAZs9u5DglQj4g$GIkKx6mVzmm5zO0TyNXDZA'

因为是服务端搭建环境,所以无需默认打开浏览器,并且允许局域网内其它主机访问jupyter notebook服务:

   c.NotebookApp.open_browser = False
   c.NotebookApp.ip = '*'

设置默认工作目录:

c.NotebookApp.notebook_dir = '/home/mia'

添加python2的内核

由于上述安装是使用 pip3 安装的 jupyter notebook,可以通过添加 python 内核,以支持创建 python2 交互式项目。下面是详细步骤:

1. 安装 python2 的 ipykernel :

pip2 install -i https://pypi.douban.com/simple ipykernel

生成 python2 的 ipykernel:

python -m ipykernel install --user

查看可用的 ipykernal::

jupyter kernelspec list

运行结果:

Available kernels:
  python2    /usr/local/share/jupyter/kernels/python2
  python3    /usr/local/share/jupyter/kernels/python3

删除某个 ipykernal: 

jupyter kernelspec remove python2

运行结果:

Kernel specs to remove:
  python2                 /usr/local/share/jupyter/kernels/python2
Remove 1 kernel specs [y/N]: y
[RemoveKernelSpec] Removed /usr/local/share/jupyter/kernels/python2 

启用 jupyter notebook

nohup jupyter notebook --no-browser --allow-root &

 

你可能感兴趣的:(环境搭建和工具使用,python)