jupyter notebook 内核管理

文章讲述了在JupyterNotebook中遇到cv2模块找不到的问题,原因是由于使用了非虚拟环境的系统conda内核。作者指导如何检查可用内核,切换到虚拟环境,安装ipykernel并为虚拟环境创建和管理JupyterNotebook内核,包括安装、显示、查看和删除内核的操作方法。
摘要由CSDN通过智能技术生成

问题:安装了cv库,但是在jupyter notebook提示No module named 'cv2'

原因:jupyter notebook 默认内核为系统conda,非虚拟环境下的内核

查看Jupyter Notebook可用内核,可在cmd中输入:
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:
  kernelname    C:\Users\Administrator\AppData\Roaming\jupyter\kernels\kernelname
  python3       D:\TEST\ANACONDA3\share\jupyter\kernels\python3

1,cmd下查看系统默认python内核版本

import sys
sys.executable

进入hack虚拟环境下查看python内核版本

.hack/venv/script/.activate
import sys
sys.executable

为虚拟环境添加jupyter notebook内核

先在虚拟环境中安装ipykernel包(内核管理工具包)

pip install ipykernel

Jupyter notebook 添加或删除内核

1、切换到要添加的虚拟环境,确认是否安装 ipykernel

python -m ipykernel –version


如果没有安装,则安装:

python -m pip install ipykernel

2、为 Jupyter notebook 添加内核

python -m ipykernel install --user --name=kernelname  --display-name hack

其中,kernelname为创建的文件夹名,showname为在Jupyter notebook展示的内核名
创建成功后,提示:
C:\Users\Administrator\AppData\Roaming\jupyter\kernels\kernelname

3、查看 Jupyter notebook kernel

jupyter kernelspec list


4、删除 jupyter 内核

jupyter kernelspec remove kernelname


补充:jupyter kernelspce 命令
No subcommand specified. Must specify one of: ['list', 'install', 'uninstall', 'remove', 'install-self', 'provisioners']

Manage Jupyter kernel specifications.

Subcommands
===========
Subcommands are launched as `jupyter kernelspec cmd [args]`. For information on
using subcommand 'cmd', do: `jupyter kernelspec cmd -h`.

list
    List installed kernel specifications.   ---列出已安装的内核规范
install
    Install a kernel specification directory.  ---安装内核规范目录。
uninstall
    Alias for remove  ---移除的别名
remove
    Remove one or more Jupyter kernelspecs by name.  ---按名称删除一个或多个Jupyter内核规范
install-self
    [DEPRECATED] Install the IPython kernel spec directory for this Python.   ---[已弃用]为这个Python安装IPython内核规范目录。
provisioners
    List available provisioners for use in kernel specifications.  ---列出内核规范中可用的配置程序。


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值