简体   繁体   English

Visual Studio Code,Anaconda 虚拟环境,具体项目?

[英]Visual Studio Code, Anaconda Virtual Environment, specific projects?

can anyone help me understand using conda environment with visual studio code?谁能帮我理解在 Visual Studio 代码中使用 conda 环境? I had activate the virtual environment (imageprocessing) with this:我已经用这个激活了虚拟环境(图像处理):

conda activate imageprocessing

and the terminal seem to have been on virtual environment, so there's look like no problem with the PATH, it looks like this.并且终端似乎一直在虚拟环境中,所以PATH看起来没有问题,看起来像这样。

(imageprocessing) ../users/[project_folder_somewhere]

But when I open visual studio code and activate the kernel used for opening Notebooks there, exactly with the python from imageprocessing virtual environment, I keep needed to install the previously forged library, for example, Pillow.但是当我打开 Visual Studio 代码并激活用于在那里打开笔记本的 kernel 时,与来自图像处理虚拟环境的 python 完全相同,我仍然需要安装以前伪造的库,例如 Pillow。 Which part that doesn't work out?哪个部分不成功? Did I install Pillow package redundantly if I keep doing this?如果我继续这样做,我是否冗余安装了 Pillow package? Does visual code doesn't integrated that well with conda even though it has been connected through the path?即使通过路径连接,视觉代码是否也不能与 conda 很好地集成? I used this feature for opening.ipynb files on Visual Studio Code because browser-based Jupyter Notebooks are too slow and messy directory than if using this (or so I thought?).我使用此功能在 Visual Studio Code 上打开 .ipynb 文件,因为与使用此功能相比,基于浏览器的 Jupyter Notebooks 太慢且目录混乱(或者我是这么认为的?)。

In VS Code, when we use different python environments, the locations where the modules are installed are different.在VS Code中,当我们使用不同的python环境时,模块安装的位置是不同的。 Therefore, we need to be clear which python environment we are currently using.因此,我们需要明确我们当前使用的是哪个python环境。 (We could check it with the command " python --version " in the VS Code terminal.) (我们可以在 VS Code 终端中使用命令“ python --version ”来检查它。)

When we use the conda environment, it comes with python, so we can use "pip" to install modules, or "conda" to install modules.当我们使用conda环境时,它自带python,所以我们可以使用“pip”安装模块,也可以使用“conda”安装模块。 The modules it installs are stored in: " ...\anaconda3\envs\conda-name\lib\site-packages ".它安装的模块存储在:“ ...\anaconda3\envs\conda-name\lib\site-packages ”。

The command " pip show pillow " checks the installation position of the module:命令“ pip show pillow ”检查模块的安装position:

在此处输入图像描述

In addition, after the installation is complete, it still shows that the module cannot be found.另外,安装完成后,还是显示找不到模块。 I noticed that there is a problem with the file name here.我注意到这里的文件名有问题。 We need to rename "PIL" to "pillow", or use "import PIL"我们需要将“PIL”重命名为“pillow”,或者使用“import PIL”

在此处输入图像描述

Reference: conda-environment in VS Code .参考: VS Code 中的 conda-environment

Add:添加:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM