VSCODE识别Conda环境,但不识别UNIX中的PIP软件包
我有一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 packageconda-forge::conda-ecosystem-user-package-isolation
.