在Windows本地用网页查看编辑服务器上的 jupyter notebook


Motivation: jupyter notebook 可以存中间变量,方便我调整代码,但是怎么用服务器的GPU并在网页上查看编辑呢?

参考 https://zhuanlan.zhihu.com/p/440080687

服务端(Ubuntu):

  1. 激活环境 source activate my_env

  2. 安装notebook pip install jupyter notebook

  3. 配置 jupyter notebook --generate-config

  4. 接下来键盘输入ipython 进入notebook ipython

  5. 一行一行输入,会返回一串hash密码,记得复制保存一下,然后按ctrl+z退出

    bash 复制代码
    In [1]: from jupyter_server.auth import passwd
    In [2]: passwd()		# 设置一个jupyter notebook的密码
    >>> argon2:$argon2id$v=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  6. 修改相应配置文件vim ~/.jupyter/jupyter_notebook_config.py,在文件末尾添加以下代码

    python 复制代码
    # 一些 Vim 命令帮助
    # 跳转到文件末尾的方法:按esc键,然后输入:$ 即可跳转到文件末尾
    # SHIFT + i 进行插入
    # ESC 退出,然后输入 wq! 进行保存
    c.NotebookApp.ip = '*'                     # 允许访问此服务器的 IP,星号表示任意 IP
    c.NotebookApp.password = 'argon2:$argon2id$v=xxxxxxxxxxxxxx' # 之前生成的密码 hash 字串, 粘贴进去
    c.NotebookApp.open_browser = False         # 运行时不打开本机浏览器
    c.NotebookApp.port = 8890                  # 使用的端口,随意设置,但是要记得你设定的这个端口
    c.NotebookApp.enable_mathjax = True        # 启用 MathJax
    c.NotebookApp.allow_remote_access = True   #允许远程访问
    c.NotebookApp.allow_root = True


    配置好后就可以直接在本地端用网页访问服务器的 jupyter notebook 了,每次从本地端连接服务器时设置好端口对应即可,如下

本地端(Windows)

  1. 进入Windows cmd

  2. 连接远程服务器,对应好端口,只要是空闲的端口即可

    bash 复制代码
    # ssh -L [本地端口]:localhost:[远程端口] [远程用户名]@[远程IP] -p [ssh连接端口,默认22]
    ssh -L 8890:localhost:8890 xx@xx.xx.xx.xx -p 22
  3. 打开虚拟环境source activate my_env

  4. 启动 jupyter notebook jupyter notebook

  5. 在浏览器中输入localhost:[本地端口],输入设定的 jupyter 密码,即可进入!

将虚拟环境配置到 jupyter notebook 中

由于 notebook用到的 ipykernel 和 python 的不一样,所以还需要将响应的虚拟环境的依赖配置到 jupyter notebook 中的 kernel 中

参考 https://blog.csdn.net/zhaoqian19921029/article/details/91382150

  1. 下载 ipykernel,通常下载 jupyter notebook 后自动下载了,用conda list看一下有没有 ipykernel 和 ipython包,没有的话conda install ipykernel

  2. 将自己的环境my_env配置到 ipykernel 中ipython kernel install --user --name=my_env

    bash 复制代码
    (my_env)xx@xxxx:xxxx$ ipython kernel install --user --name=my_env
    >>> Installed kernelspec safemllm in /home/jd/.local/share/jupyter/kernels/safemllm
  3. 再打开 jupyter notebook 的 web 页面就可以在 Select Kernel 里看见和选择自己的环境了

相关推荐
我不要放纵10 分钟前
LVS集群搭建
linux·服务器·lvs
阿巴~阿巴~15 分钟前
自主Shell命令行解释器
linux·运维·服务器
SHUIPING_YANG41 分钟前
根据用户id自动切换表查询
java·服务器·数据库
chao_7891 小时前
更灵活方便的初始化、清除方法——fixture【pytest】
服务器·自动化测试·python·pytest
枷锁—sha1 小时前
【DVWA系列】——CSRF——Medium详细教程
android·服务器·前端·web安全·网络安全·csrf
枷锁—sha1 小时前
跨站请求伪造漏洞(CSRF)详解
运维·服务器·前端·web安全·网络安全·csrf
scuter_yu1 小时前
腾讯云云服务器深度介绍
服务器·云计算·腾讯云
群联云防护小杜2 小时前
深度隐匿源IP:高防+群联AI云防护防绕过实战
运维·服务器·前端·网络·人工智能·网络协议·tcp/ip
van叶~2 小时前
Linux探秘坊-------15.线程概念与控制
linux·运维·服务器
2301_780789666 小时前
UDP和TCP的主要区别是什么
服务器·网络协议·web安全·网络安全·udp