简体   繁体   English

VS Code 上的 Anaconda 环境

[英]Anaconda Environment on VS Code

In general I am new to python so keep it easy.一般来说,我是python的新手,所以请保持轻松。 I have started my coding in Spyder since it was easy to install libraries with Anaconda.我已经开始在 Spyder 中编码,因为使用 Anaconda 安装库很容易。

Now we want to switch to VS Code for version control.现在我们要切换到 VS Code 进行版本控制。 I have switched interpreter and python path to Anaconda folder, but if I open python files I have created in Spyder I can't use in VS code, issue always is with importing libraries.我已经将解释器和 python 路径切换到 Anaconda 文件夹,但是如果我打开在 Spyder 中创建的 python 文件,我无法在 VS 代码中使用,问题总是与导入库有关。

Screenshot截屏

The first rule with Anaconda is to not manually mess around with the paths. Anaconda 的第一条规则是不要手动弄乱路径。 Anaconda has a different philosophy: Before you can use Python, you need to activate a conda environment. Anaconda 有不同的理念:在使用 Python 之前,您需要激活 conda 环境。

c:\> conda activate
(Anaconda3) c:\> python
>>>

VSCode detects conda environments and you just have to select one for your project (Python: Select interpreter). VSCode 检测 conda 环境,您只需为您的项目选择一个环境(Python:选择解释器)。 Now open a new terminal and watch VSCode activating the environment for you (like shown above).现在打开一个新终端并观看 VSCode 为您激活环境(如上所示)。

However, when you start your script for the first time, VSCode sometimes invokes the interpreter even before the conda activation has finialized.但是,当您第一次启动脚本时,VSCode 有时甚至在 conda 激活完成之前调用解释器。 Then simply restart your script.然后只需重新启动您的脚本。

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

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