美文网首页
win10安装Jupyter notebook,开启外网访问

win10安装Jupyter notebook,开启外网访问

作者: 晓函 | 来源:发表于2023-03-02 11:41 被阅读0次

实机安装jupyter

新建cmd窗口,本地环境配置(不是虚拟环境)

pip install jupyter

创建虚拟环境

1、创建venv

d:\
cd d:\pyvenv
python -m venv tensorflow2_venv
tensorflow2_venv\Scripts\activate

2.安装ipykernel
在Jupyter Notebook中,有一个叫做IPython内核的东西,它本质上是在后端执行Python代码的计算引擎。
为了向IPython内核注册venv,需要在【虚拟环境】中pip安装模块ipykernel,然后注册当前py venv环境

#安装ipykernel以便向jupyter的ipython注册此py环境
pip install ipykernel
#向ipykernel注册此py环境
python -m ipykernel install --name=tensorflow2_venv
image.png

如需删除 kernel中的某个venv,用下面代码

jupyter kernelspec uninstall tensorflow2_venv

实机配置jupyter

1、生成远程访问密码sha(如果不设置密码,则跳过这一步)

ipython
from notebook.auth import passwd
passwd()
#输入两次密码后,得到密码加密sha
#退出
quit()
image.png

2、生成jupyter空配置文件

jupyter notebook --generate-config

3.修改jupyte配置文件
包括密码,端口号,默认文件地址,当然ip也可以限制死,'*'是不限制:

打开刚才的地址,C:\Users\Family.jupyter\jupyter_notebook_config.py
用记事本打开这个python文件添加如下几行命令:

c.NotebookApp.password = u'argon2:$argon2id$v=19$m=10240,t=10,p=8$g6xxx'  # 在u后的引号内输入上一步复制的密码sha
# disable authentication 免密码登录
#c.NotebookApp.token = ''     
# ip设置为*表示全部
c.NotebookApp.ip='*'   
# 禁止在运行ipython的同时弹出浏览器
c.NotebookApp.open_browser = False 
# allow access from anywhere
c.NotebookApp.allow_origin = '*' 
# allow cross-site requests
c.NotebookApp.disable_check_xsrf = True
#可自行指定一个端口, 访问时使用该端口,默认8888
c.NotebookApp.port = 8888     
#设置jupyter-notebook的工作空间,注意linux与windows的路径表示方式
c.NotebookApp.notebook_dir = 'D:\Projects\Jupyter' 
image.png

运行jupyter

jupyter-notebook

如果需要开机自动打开,需要添加到计划任务

访问jupyter

#本机访问
localhost:8888
#局域网访问
10.0.0.6:8888

如果需要外网访问,需要1、有公网ip,2、在路由设置端口转发到8888


image.png

http://公网ip:8888

测试

我们的虚拟环境tensorflow2_venv 已经添加到jupyter


image.png

相关文章

网友评论

      本文标题:win10安装Jupyter notebook,开启外网访问

      本文链接:https://www.haomeiwen.com/subject/srkjldtx.html