在Visual Studio Code中使用Anaconda [英] Working with Anaconda in Visual Studio Code
问题描述
我在这里有点困惑,在撰写本文时,最新的Anaconda发行版(2018.12)带有安装Microsoft Visual Studio Code的选项,这很棒.
I am getting a bit confused here, the latest Anaconda Distribution, 2018.12 at time of writing comes with an option to install Microsoft Visual Studio Code, which is great.
启动VSC之后,在Python: Select Interpreter
之后并重新安装Anaconda,我可以看到~Anaconda3\python.exe
,我认为是Anaconda Python Environment,但是,当我尝试运行一些命令时,却得到了: >
When launching VSC and after Python: Select Interpreter
and with a fresh install of Anaconda, I can see ~Anaconda3\python.exe
which I assume is the Anaconda Python Environment, however, when I try to run some commands, I am getting:
PS ~\Documents\Python Scripts\vs> ~/Anaconda3/Scripts/activate
PS ~\Documents\Python Scripts\vs> conda activate base
conda:术语'conda'不被视为cmdlet的名称, 功能,脚本文件或可操作程序.检查拼写 名称,或者如果包含路径,请验证路径是否正确,以及 再试一次.在第1行:char:1
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1
现在,我知道它可能与环境变量有关,但是我发现它与Anaconda安装过程中的异常情况非常相似,特别提到无需将Anaconda路径添加到环境变量中.但是,发生错误后,集成终端可以启动Python,并且我能够运行代码.
Now I know that it might be related to the environment variables but I find it highly odd as during the Anaconda installation, there are specific mentions that it is not required to add the Anaconda path to the environment variables. However after the error, the integrated terminal manages to launch Python and I am able to run code.
接下来的内容是,运行简单的脚本后,我无法在调试器中查看任何变量,如教程此处:
Next in line is that I am unable to view any variables in the debugger after running a simple script, as shown in the tutorial here:
msg = "Hello World"
print(msg)
我确实希望看到链接中显示的类似结果,例如dunder变量,我还按照以下步骤用stopOnEntry = True
更新了launch.json
.
I do expect to see similar results as shown in the link such as the dunder variables, I have also updated my launch.json
with stopOnEntry = True
following the steps.
我想知道是否可以将Visual Studio Code与Anaconda一起用作解释器,而无需注册原始发行版本中的变量,并且是否遗漏了任何必需的内容.
I would like to know if it is possible to use Visual Studio Code with Anaconda as a interpreter without registering variables from the original distribution and if I am missing out anything required.
我希望体验会更加直接,但是我可能会丢失某些东西,因为我正在Windows 10上运行.
I expected the experience to be more straight forward but also I might be missing something, I am running on Windows 10.
推荐答案
激活conda环境不会将conda
放置在您的PATH
上.如果未在安装过程中选中包含conda
的框,则需要从开始"菜单启动Anaconda Prompt
应用程序,以在PATH
上获得带有conda
的命令行.
Activating a conda environment does not place conda
on your PATH
. You need to launch the Anaconda Prompt
app from your Start menu to get a command-line with conda
on your PATH
if you didn't check the box to include conda
during installation.
还意识到,conda
自2019年1月发布的conda
4.6起仅支持PowerShell.
Also realize that conda
only supports PowerShell as of conda
4.6 which was released in January 2019.
并且VS Code的Python扩展可以很好地使用conda
.创建一个conda
环境,该扩展名将使您可以选择它作为您的环境/解释器.
And the Python extension for VS Code works with conda
fine. Create a conda
environment and the extension will allow you to select it as your environment/interpreter.
这篇关于在Visual Studio Code中使用Anaconda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!