目录
安装
- 基础安装,在python的虚拟环境下运行pip install jupyter安装jupyter notebook
- 检查基础安装是否成功,运行以下命令,jupyter notebook服务启动,默认打开浏览器,窗口显示的是当前目录
C:\Python36\envs\py365\Scripts>jupyter notebook
- 在C:\Users\用户名\目录下会出现.jupyter文件夹
配置
阿里云服务器上基础安装成功后,开始配置
云服务器上安装需要设置密码
在python命令行写上如下代码:
from notebook.auth import passwd
passwd()
输入密码,再次输出确认密码
'sha1:e76d3796d801:95c86a78cfc68d55759c45cc02e33ea5d4dbb532'
输出以上sha1
在虚拟环境命令行运行:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem
过程中要求输入国家省城市等一堆,最后将在当前目录生成两个文件mykey.key, mycert.pem
基础安装进入jupyter界面是不需要输入密码的,本文的目的是任意电脑访问,所以接下下进行密码设置
1. 生成配置文件C:\Users\Administrator\.jupyter\jupyter_notebook_config.py
在jupyter.exe目录下运行命令:我这里是在虚拟环境下
C:\Python36\envs\py365\Scripts>jupyter notebook --generate-config
输出:Writing default config to: C:\Users\用户名\.jupyter\jupyter_notebook_config.py
2. 修改并保存配置文件
在jupyter_notebook_config.py文件最后添加如下内容
c.NotebookApp.password = u'sha1:e76d3796d801:95c86a78cfc68d55759c45cc02e33ea5d4dbb532' #上面第二步中生成的密钥
c.NotebookApp.certfile = u'c:/jpyb/mycert.pem' # 指定文件路径
c.NotebookApp.keyfile = u'c:/jpyb/mykey.key' # 指定文件路径
c.NotebookApp.ip = '*'
c.NotebookApp.notebook_dir = 'c:/jpyb' # 指定notebook的工作目录
c.NotebookApp.open_browser = False # 在服务启动后,是否打开浏览器
c.NotebookApp.port = 8898 # 服务器的端口
3. 在命令行运行jupyter notebook
命令
如果已经添加了jupyter.exe路径到环境变量中请直接运行,如果没有请定位到exe目录运行,运行后正常是这样的提示:
[I 13:39:59.125 NotebookApp] Serving notebooks from local directory: c:/jpyb
[I 13:39:59.125 NotebookApp] The Jupyter Notebook is running at:
[I 13:39:59.125 NotebookApp] https://(你的计算名 or 127.0.0.1):8898/
[I 13:39:59.125 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
到此,已经可以在本机上打开https://127.0.0.1:8898/
,即出现jupyter notebook密码输入窗口。注意一定要https
但在任意电脑上打开https://公网ip:8898/
是不可以的,以下解决此问题。
4. 在阿里云服务器按以下配置:
【云服务器管理控制台】【云服务器ECS】【网络和安全】【安全组】【配置规则】添加安全组规则
上图是借来的,端口号按自己的修改
5. 重启服务
在windows命令行按下CTRL+C停止jupyter服务,再次运行jupyter notebook
启动服务,任意电脑就可以访问https://公网ip:8898/
了。
参考资料:
在服务器上配置jupyter notebook
官方资料
如何在云服务器上设置可远端访问的jupyter notebook