jupyter 安装新内核后报找不到已安装的包

按照参考资料1 在jupyter notebook 安装上新内核后,发现在命令行里可以导入已安装的包,但在jupyter notebook 无法导入对应的包

通过调试,发现jupyter 安装新内核的python 环境的执行文件不是新内核的python执行文件,而是conda 里base 环境的pthon执行文件,所以虽然安装了新内核,但执行文件没有更改,所以也没有生效

环境如下

IPython : 8.15.0

ipykernel : 6.25.0

ipywidgets : 8.0.4

jupyter_client : 7.4.9

jupyter_core : 5.3.0

jupyter_server : 1.23.4

jupyterlab : 3.6.3

nbclient : 0.5.13

nbconvert : 6.5.4

nbformat : 5.9.2

notebook : 6.5.4

qtconsole : 5.4.2

traitlets : 5.7.1

conda 23.7.4,python 3.11版本,jupyter notebook 版本6.5.4,ubuntu 20.04 环境, 通过jupyter kernelspec list 命令查看安装新内核的位置,如我的环境的输出为

torch /home/xxx/.local/share/jupyter/kernels/torch

python3 /home/xxx/anaconda3/share/jupyter/kernels/python3

其中python3 为默认jupyter 内核,torch 为新安装的内核,进入torch 的安装目录,里面会有如下一个文件

-rw-rw-r-- 1 xxx xxx 205 9月 2 11:20 kernel.json

vim 打开这个文件

打开jupyter 的配置文件

{

"argv": [

"/home/xxx/anaconda3/bin/python",

"-m",

"ipykernel_launcher",

"-f",

"{connection_file}"

],

"display_name": "torch",

"language": "python",

"metadata": {

"debugger": true

}

}

可以看到argv的环境里配置的python 执行文件为conda 的默认python 执行,把它修改为torch 的执行文件/home/xxx/anaconda3/envs/torch/bin/python,保存,重启jupyter notebook 即可,发现环境已修改为torch 的环境

由于新的内核可能没有安装ipykernel 导致报错 No module named ipykernel_launcher

I 11:47:30.084 NotebookApp\] KernelRestarter: restarting kernel (1/5), new random ports,这时只要在新的内核下安装ipykernel 即可 pip install ipykernel 在windows 系统下,也是一样 参考资料 1 [jupyter notebook添加、删除内核_jupyter卸载内核-CSDN博客](https://blog.csdn.net/I_LOVE_MCU/article/details/108311698 "jupyter notebook添加、删除内核_jupyter卸载内核-CSDN博客")

相关推荐
2301_803934611 天前
Go语言如何做网络爬虫_Go语言爬虫开发教程【指南】
jvm·数据库·python
WL_Aurora1 天前
Python爬虫实战(六):新发地蔬菜价格数据采集.
爬虫·python
盲敲代码的阿豪1 天前
Python 入门基础教程(爬虫前置版)
开发语言·爬虫·python
weixin199701080161 天前
[特殊字符] 智能数据采集:数字化转型的“数据石油勘探队”(附Python实战源码)
开发语言·python
次元工程师!1 天前
LangFlow开发(三)—Bundles组件架构设计(3W+字详细讲解)
java·前端·python·低代码·langflow
t_hj1 天前
大模型微调
人工智能·python·深度学习
范范@1 天前
python基础-函数
开发语言·python
2301_803934611 天前
MySQL 字段类型选择规范指南
jvm·数据库·python
yaoxin5211231 天前
406. Java 文件操作基础 - 字符与二进制流
java·开发语言·python
一勺菠萝丶1 天前
macOS 安装 Python 包报错:`externally-managed-environment` 怎么解决?
python