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启动 这回就正常了。

相关推荐
无声旅者12 分钟前
深度解析 IDEA 集成 Continue 插件:提升开发效率的全流程指南
java·ide·ai·intellij-idea·ai编程·continue·openapi
学地理的小胖砸21 分钟前
【Python 操作 MySQL 数据库】
数据库·python·mysql
安迪小宝23 分钟前
6 任务路由与负载均衡
运维·python·celery
Blossom.11825 分钟前
使用Python实现简单的人工智能聊天机器人
开发语言·人工智能·python·低代码·数据挖掘·机器人·云计算
lisw0536 分钟前
Python高级进阶:Vim与Vi使用指南
python·vim·excel
ayiya_Oese1 小时前
[模型部署] 3. 性能优化
人工智能·python·深度学习·神经网络·机器学习·性能优化
SoraLuna1 小时前
「Mac畅玩AIGC与多模态40」开发篇35 - 用 Python 开发服务对接 SearxNG 与本地知识库
python·macos·aigc
noravinsc2 小时前
redis是内存级缓存吗
后端·python·django
王学政22 小时前
LlamaIndex 第九篇 Indexing索引
人工智能·python
百锦再2 小时前
大数据技术的主要方向及其应用详解
大数据·linux·网络·python·django·pygame