我已经使用Anaconda创建了一个虚拟环境,并根据需求文本文件安装了我需要的所有软件包。然后安装ipykernel。这是我使用的代码。
conda create --name venv_nlp python=3.8
conda activate venv_nlp
pip install -r requirements.txt
python -m ipykernel install --user --name=venv_nlp
之后,我在anaconda提示符中输入pip list来查看安装的包列表。我需要的包bertopic在列表中。
我已经打开我的Jupyternotebook,将内核更改为venv_nlp。但是,当运行
时from bertopic import BERTopic
我得到一个错误:
C:ProgramDataAnaconda3libsite-packagesipykernelipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
and should_run_async(code)
当我这样做
!pip list
我得到一个警告和安装的软件包列表。Bertopic不在里面:
C:ProgramDataAnaconda3libsite-packagesipykernelipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
and should_run_async(code)
我的虚拟环境路径是C:ProgramDataAnaconda3envsvirtualenv_nlp似乎代码正在寻找C:ProgramDataAnaconda3libsite-packages中的包。这样就创建了一个ModuleNotFoundError
我可以知道这里应该怎么做吗?我对创建虚拟环境还是个新手。
此错误可能由以下几个原因引起:
- 软件包bertopic不应该正确安装,因此您可以重新安装在激活venv_nlp环境时安装此包:
重新安装命令
pip install bertopic
- 您的环境中可能缺少一些依赖项。在激活venv_nlp环境时,可以使用以下命令:
pip install -r requirements.txt