关于 jupyter notebook 在 win下的虚拟环境添加问题

本文介绍了如何在Windows环境下,不依赖conda,通过Python命令创建并添加名为env-py11的虚拟环境到JupyterNotebook中,以及如何配置和管理这些环境,包括查看、添加、删除和切换虚拟环境的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


参考:在 Jupyter Notebook 和 Python 中使用虚拟环境 - njanakiev

windows 上

这里不借助 conda 及其其它 python 版本管理工具,就是自己通过 python 命令或 pycharm 创建的一个 python 虚拟环境,我暂且命名为 env-py11,它在我的 E 盘。

以下是在 win 上实现,mac,linux,conda 等见上面链接里的方法。

# 前提
pip install --user ipykernel


# 查看当前 jupyter 所有的环境
(env-py311) C:\Users\xulon\Desktop>jupyter kernelspec list
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Available kernels:
  python3    D:\Python\Python311\share\jupyter\kernels\python3


# 添加虚拟环境 env-py311 到 jupyter
(env-py311) C:\Users\xulon\Desktop>python -m ipykernel install --user --name=env-py311
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Installed kernelspec env-py311 in C:\Users\xulon\AppData\Roaming\jupyter\kernels\env-py311


# 查看
(env-py311) C:\Users\xulon\Desktop>jupyter kernelspec list
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Available kernels:
  env-py311    C:\Users\xulon\AppData\Roaming\jupyter\kernels\env-py311
  python3      D:\Python\Python311\share\jupyter\kernels\python3

# 但此时 env-py311 的实际并不是你想要的那个环境,它只是一个名字
# list 查看 env-py11 在 jupyter 里的位置,修改kernel.json,吧argv里的路径换成你自己的虚拟环境的位置
# 再运行 jupyter-lab 或者 jupyter notebook
# 切换“内核”为自己的虚拟环境即可

# 删除指定环境
jupyter kernelspec uninstall env-py311

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值