jupyter安装过程详解
1 python安装
详见 https://blog.csdn.net/weixin_44856211/article/details/138067435
2 虚拟环境创建
详见 https://blog.csdn.net/weixin_44856211/article/details/138067435
3 安装jupyter
3.1 进入虚拟环境
# 创建虚拟环境
[root@localhost ~]# mkvirtualenv jupyter-test
# 进入虚拟环境
[root@localhost ~]# workon jupyter-test
(jupyter-test) [root@localhost ~]#
3.2 安装jupyter
# 安装jupyter(时间很长,此处未指定版本,安装最新版本)
(jupyter-test) [root@localhost ~]# pip install jupyter
3.3 生成配置文件
# 注意,此处很可能出现urllib3版本与OpenSSL不兼容问题,可通过降低urllib3版本或者升级OpenSSL解决
# 配置文件路径:/root/.jupyter/jupyter_notebook_config.py
(jupyter-test) [root@localhost ~]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
3.4 生成密码串
# 生成的密码串须保留,后续使用
(jupyter-test) [root@localhost ~]# python
Python 3.8.10 (default, Apr 22 2024, 21:36:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from jupyter_server.auth import passwd # 注意notebook的版本, 7.0.0版本后无from notebook.auth import passwd
>>> passwd()
Enter password:
Verify password:
'argon2:$argon2id$v=19$m=10240,t=10,p=8$Fy4Eo2fOW34puZX6crT8MA$IJVXreHT7EcoipniXhA7QKHjiW3sPyc2tG24mquCO3o'
>>>
3.5 创建Jupyter的根目录
# Jupyter的根目录(ipython文件保存的路径,就是自己的代码文件目录)
mkdir /root/jupyter-code
3.6 修改默认配置文件
# 配置文件路径:/root/.jupyter/jupyter_notebook_config.py
# 禁止notebook启动时自动打开浏览器(在linux服务器一般都是ssh命令行访问,没有图形界面的。所以,启动也没啥用)
c.JupyterNotebookApp.open_browser = False
# 设置访问notebook的ip,*表示所有IP,这里设置ip为都可访问
c.NotebookApp.ip = '0.0.0.0'
# 设置密码,填写刚刚生成的密文
c.NotebookApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$Fx0E0ADBpKq2aImpmNg8vw$afKVOPunf/e4BF/P24vAI7Iakk1hG8febpxXqmPjgqk'
# 指定访问的端口,默认是8888
c.NotebookApp.port = 7777
# 允许以root权限启动jupyter
c.NotebookApp.allow_root = True
# 这里是设置Jupyter的根目录(ipython文件保存的路径,就是自己的代码文件目录)
c.NotebookApp.notebook_dir = '/root/jupyter-code'
3.7 启动notebook
(jupyter-test) [root@localhost jupyter-test]# jupyter notebook --allow-root
3.8 访问notebook
# 此处无法访问的话,试试关闭防火墙
http://本机ip:7777/tree