1 搭建jupyter notebook运行环境
参考:https://blog.csdn.net/qq_24027563/article/details/80589880
# 1.创建虚拟环境
conda create -n jupyter python=3.7
# 2. 安装Jupyter 包
conda install jupyter
# 3.获取默认配置地址
jupyter notebook --generate-config
# 4. 创建密码密文,记住对应的明文和密文
# 我的明文:sunie
# 我的密文:sha1:341f5715c4a2:168a7db6baaefd7ad5e1500de685b4e74766a252
# sha1:27957f7a7344:0b1c104afca3ace5e6c593facf140df2f37f7e3c
python -c "import IPython; print(IPython.lib.passwd())"
# python>3.8上述方法已失效:AttributeError: module 'IPython.lib' has no attribute 'passwd'
python -c "from notebook.auth import passwd; print(passwd())"
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'argon2:$argon2id$v=19$m=10240,t=10,p=8$Dv+PEdPpQjD9S+idxJmj/Q$fzSCFBoeJFjejJ1fNIiBYeqMxsisfDkrR7aNLgGhN6g'
把密码串拷贝到剪切板
编辑该文件vim ~/.jupyter/jupyter_notebook_config.py
,G
底端添加:
c = get_config()
# 所有matplotlib的图像都通过iline的方式显示
c.IPKernelApp.pylab = 'inline'
# 指向创建的ssl证书
c.NotebookApp.certfile = u'/Server/nginx/sunie.top_chain.crt'
c.NotebookApp.keyfile = u'/Server/nginx/sunie.top_key.key'
# 给出刚刚创建的密码的哈希值
c.NotebookApp.password = u'sha1:341f5715c4a2:168a7db6baaefd7ad5e1500de685b4e74766a252'
c.NotebookApp.ip = '*'
c.NotebookApp.allow_origin = '*'
# 给出运行的端口
c.NotebookApp.port = 9001
# 禁止在运行ipython的同时弹出浏览器
c.NotebookApp.open_browser = False
使用以下命令启动
setsid jupyter notebook --allow-root
启动成功!并且使用的是https,可以正常运行代码
2 侧边导航栏功能 操作及其他常用扩展功能介绍
pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install --user
安装完成后重启 Jupyter Notebook,出现如下界面,新增Nbextensions一栏,勾选Table of Contents (2)
其他功能按需选择。详见:https://www.cnblogs.com/likedata/p/11225252.html
3 docker运行方式
使用如下命令自动下载,官网见https://hub.docker.com/r/jupyter/datascience-notebook
setsid docker run --rm -p 9007:8888 \
--name datascience \
-e JUPYTER_ENABLE_LAB=yes \
-v /Server/datascience:/home/jovyan/work \
jupyter/datascience-notebook
4 连接已重置
打开网页发现连接已重置,服务器上显示:
原因未知
因为访问前必须加上 https
5 无法连接到内核
试过
- pip install --upgrade ipython ipykernel
- pip install tornado==4.5.3
- 重新安装conda install jupyter
- 降级python到3.8
- 升级python到3.10
- 降级python到3.7
均失效。为了证明不是一个机器的问题,在NAS上进行同样的尝试,发现完全是可行的
why???
https://www.cnblogs.com/damin1909/p/12691147.html
原因是在nginx反向代理过程与jupyter有冲突,使用域名访问即可
评论区