已将python包安装到conda虚拟环境,Jupyter笔记本中的ModuleNotFoundError

2024-06-16 13:24:01 发布

您现在位置:Python中文网/ 问答频道 /正文

从虚拟环境中的Anaconda提示符安装python包。 import transformers在Anaconda提示符下工作。但是,即使内核被设置为安装包的虚拟环境,在Jupyter笔记本中也会出现ModuleNotFoundError

看起来这个问题与 Jupyter notebook can't load installed package in conda environment,但我无法让它在Windows上工作

这里有一个例子

Package is installed in the virtual environment.

Importing from the anaconda prompt works.

Importing from Jupyter Notebook causes the error.


Tags: installedtheinfromimportenvironment虚拟环境笔记本
2条回答

从命令行打开Jupyter笔记本。首先激活conda环境

  1. 打开命令行。激活您的康达环境。 键入activate <your env name>

  2. 键入jupyter notebook <path to your project>。要在当前目录中打开jupyter notebook .

该软件包最初是使用conda install -c conda-forge transformers安装的

相反,我使用pip install transformers安装了打包的。从虚拟环境内核上的Jupyter Notebook导入包之后效果很好

当我从虚拟环境中执行where conda时,conda install似乎没有安装到venv。而where pip表明venv's pip正在被使用

相关问题 更多 >