VSCODE识别Conda环境,但不识别UNIX中的PIP软件包

发布于 2025-01-31 20:03:29 字数 753 浏览 2 评论 0原文

我有一个conda环境conda_env,我在Visual Studio Code上的Jupyter笔记本中激活了该环境。该环境包含使用conda安装pip install安装的软件包。

笔记本电脑位于远程服务器上的Unix Shell中。我能够进口与conda安装的软件包,并居住在环境路径内(miniconda/envs/conda_env /...)。但是,当我尝试导入使用PIP安装的软件包时,导入失败。

ModuleNotFoundError: No module named 'django-extensions'

如果我在Conda环境内的命令行上启动Python环境,则可以导入软件包。下面显示了包裹的路径。

import django_extensions
print(django_extensions.__file__)
# ~/.local/lib/python3.9/site-packages/django_extensions/__init__.py

我最终通过将此行放入笔记本电脑中找到了解决方案。

sys.path.append("~/.local/lib/python3.9/site-packages/")

我的问题是,是否有一种方法可以在整个VSC中进行此操作,而无需我在每个笔记本中手动将这一行插入?

谢谢你!

I have a conda environment conda_env, which I activate in a Jupyter notebook on Visual Studio Code. The environment contains packages installed using both conda install and pip install.

The notebook resides in a Unix shell on a remote server. I am able to import packages installed with conda and residing inside the environment path (miniconda/envs/conda_env/...). However, when I try to import packages that were installed with pip, the import fails.

ModuleNotFoundError: No module named 'django-extensions'

I can import the packages if I start a Python environment on the command line inside the conda environment. Below shows the path the package is found in.

import django_extensions
print(django_extensions.__file__)
# ~/.local/lib/python3.9/site-packages/django_extensions/__init__.py

I eventually found a workaround solution by putting this line into the notebook.

sys.path.append("~/.local/lib/python3.9/site-packages/")

My question is, is there a way to do this across the entire VSC, without me having to manually put that line in inside every notebook?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱格式化 2025-02-07 20:03:29

sys.path.append(“〜/.local/lib/python3.9/site-packages/”)

solves” 使用pip install -user安装,该通常是不建议使用Conda用户。如果您想在环境中使用PIP安装,请不要使用- 用户标志。

在用户站点中安装软件包会导致用户混淆,我建议用户完全避免使用它们(删除任何〜/.local/lib/python*)或安装软件包conda-forge: :conda-ecosystem-user-package-isolation

The fact that

sys.path.append("~/.local/lib/python3.9/site-packages/")

"solves" the issue indicates that the packages were installed with pip install --user which is not installing into the environment and generally is not recommended for Conda users. If you wish to install with Pip in an environment, do not use the --user flag.

Having packages installed in user site leads to confusion among users and I recommend users either avoid them altogether (delete any ~/.local/lib/python*) or install the package conda-forge::conda-ecosystem-user-package-isolation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文