Windows下建立Jupyter-lab 编程环境

Windows下建立Jupyter-lab 编程环境

方法1在python 虚拟环境下启动(失败)

首先激活环境

进入python的scripts目录,执行激活文件:

复制代码
cd py311\Scripts
activate.bat

安装jupyter

复制代码
pip install jupyter -U

启动jupyter-lab

进入工作目录,比如e:盘根目录,执行

复制代码
jupyter-lab

但是用这种方法报错kernel没有找到,后面有详细的调试信息。

方法2 在Anaconda的PowerShell环境下启动

直接windows里快捷图标启动Anaconda的Powershell环境,shell里切换到e:盘,然后执行jupyter-lab启动,这样jupyter-lab就启动了。

很简单是不是?在顺利的情况下,windows下的程序就启动就是这么简单方便。

总结

在Windows下,最快启动jupyter-lab的方法,是安装Anaconda ,然后到Powershell环境里,切换到工作目录后,执行jupyter-lab启动。如果不考虑设置工作目录,使用默认目录的话,直接用启动菜单里的Jupyter notebook 图标启动即可。

前面之所以走了弯路,是因为在Linux、FreeBSD下习惯了创建虚拟python环境,在虚拟环境安装各种软件,而这次在windows下虚拟环境里的内核没有注册上来导致的。也就是既然选了Windows,也就别整那么多虚拟python环境了,换句话说,即使要整,直接多安装一个Anaconda软件就好了,这样肯定不会出问题。

调试

jupyter-lab启动后报错kernel没有找到

E 2025-01-20 09:31:48.385 ServerApp\] 500 PUT /api/contents/work/five/Untitled.ipynb?1737336708309 (02c6c05c95694255880b6c0209b701c3@::1) 73.21ms referer=http://localhost:8888/lab/tree/work/five/Untitled.ipynb \[W 2025-01-20 09:31:49.282 ServerApp\] 404 GET /api/kernels/88bf4ba0-dd94-4d23-8b4f-a41826aa36f0?1737336709278 (::1): Kernel does not exist: 88bf4ba0-dd94-4d23-8b4f-a41826aa36f0 \[W 2025-01-20 09:31:49.282 ServerApp\] wrote error: 'Kernel does not exist: 88bf4ba0-dd94-4d23-8b4f-a41826aa36f0' Traceback (most recent call last): File "E:\\py311\\Lib\\site-packages\\tornado\\web.py", line 1790, in _execute result = await result \^\^\^\^\^\^\^\^\^\^\^\^ File "E:\\py311\\Lib\\site-packages\\jupyter_server\\auth\\decorator.py", line 73, in inner return await out \^\^\^\^\^\^\^\^\^ File "E:\\py311\\Lib\\site-packages\\jupyter_server\\services\\kernels\\handlers.py", line 75, in get model = await ensure_async(km.kernel_model(kernel_id)) \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^ File "E:\\py311\\Lib\\site-packages\\jupyter_server\\services\\kernels\\kernelmanager.py", line 508, in kernel_model self._check_kernel_id(kernel_id) File "E:\\py311\\Lib\\site-packages\\jupyter_server\\services\\kernels\\kernelmanager.py", line 539, in _check_kernel_id raise web.HTTPError(404, "Kernel does not exist: %s" % kernel_id) tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 88bf4ba0-dd94-4d23-8b4f-a41826aa36f0) 查找当前内核 Available kernels: python3 E:\py311\share\jupyter\kernels\python3 查看内核目录: dir E:\py311\share\jupyter\kernels\python3 驱动器 E 中的卷是 新加卷 卷的序列号是 CA89-671D E:\py311\share\jupyter\kernels\python3 的目录 2025/01/20 09:29

. 2025/01/20 09:29 .. 2025/01/20 09:29 193 kernel.json 2025/01/20 09:29 1,084 logo-32x32.png 2025/01/20 09:29 2,180 logo-64x64.png 2025/01/20 09:29 9,605 logo-svg.svg 4 个文件 13,062 字节 2 个目录 845,146,857,472 可用字节 打开内核配置文件kernel.json notepad E:\py311\share\jupyter\kernels\python3\kernel.json 发现conda目录跟当前env环境目录不一致: base environment : E:\Program Files\anaconda (writable) 现在的解决方法有两个:要么在内核设置这里改一下,要么用conda env 里的环境激活一下。 我们先尝试第一种方法: 修改内核配置文件,将"python" 修改成"E:\\py311\\Scripts\\python.exe" ,问题没有解决。 尝试第二种方法 直接进入mini conda mini 环境,然后执行jupyter-lab 结果还是报错 File "E:\Program Files\anaconda\Lib\site-packages\prompt_toolkit\styles\from_dict.py", line 9, in from collections import Mapping ImportError: cannot import name 'Mapping' from 'collections' (E:\Program Files\anaconda\Lib\collections\__init__.py) [W 2025-01-20 09:46:52.779 ServerApp] AsyncIOLoopKernelRestarter: restart failed [W 2025-01-20 09:46:52.780 ServerApp] Kernel 2eb1e25f-9d86-4d77-aaa4-71e3b9403611 died, removing from map. [W 2025-01-20 09:47:34.641 ServerApp] Timeout waiting for kernel_info reply from 2eb1e25f-9d86-4d77-aaa4-71e3b9403611 [W 2025-01-20 09:47:34.644 ServerApp] 404 GET /api/kernels/2eb1e25f-9d86-4d77-aaa4-71e3b9403611/channels?session_id=b33f0ee6-c840-431e-bb42-43efd6fc6dd8 (::1): Kernel does not exist: 2eb1e25f-9d86-4d77-aaa4-71e3b9403611 [W 2025-01-20 09:47:34.918 ServerApp] Timeout waiting for kernel_info reply from 2eb1e25f-9d86-4d77-aaa4-71e3b9403611 [W 2025-01-20 09:47:34.921 ServerApp] 404 GET /api/kernels/2eb1e25f-9d86-4d77-aaa4-71e3b9403611/channels?session_id=2dce7765-d068-4e8a-b26d-6832a6e6801e (127.0.0.1): Kernel does not exist: 2eb1e25f-9d86-4d77-aaa4-71e3b9403611 明白了,它还是找到的anaconda,素以还是进入anaconda的环境试试吧。 直接快捷图标启动anaconda jupyter notebook,但是目录是默认目录。于是还是到anaconda的powershell环境里,切换到e:盘后,执行jupyter-lab启动 这回就正常了。

相关推荐
weixin1997010801644 分钟前
[特殊字符] 智能数据采集:数字化转型的“数据石油勘探队”(附Python实战源码)
开发语言·python
次元工程师!1 小时前
LangFlow开发(三)—Bundles组件架构设计(3W+字详细讲解)
java·前端·python·低代码·langflow
t_hj2 小时前
大模型微调
人工智能·python·深度学习
范范@2 小时前
python基础-函数
开发语言·python
2301_803934612 小时前
MySQL 字段类型选择规范指南
jvm·数据库·python
сокол3 小时前
【网安-Web渗透测试-内网渗透】域环境权限维持
服务器·windows·网络安全·系统安全
yaoxin5211234 小时前
406. Java 文件操作基础 - 字符与二进制流
java·开发语言·python
一勺菠萝丶4 小时前
macOS 安装 Python 包报错:`externally-managed-environment` 怎么解决?
python
醒李5 小时前
盲人出行辅助系统原型
人工智能·python·目标检测
PILIPALAPENG5 小时前
第4周 Day 3:多 Agent 协作——让 Agent 们"组队干活"
前端·人工智能·python