首页 > 解决方案 > 如何同时激活 Anaconda 环境和 Typescript 观察者?

问题描述

    "terminal.integrated.shellArgs.windows": [
        "-ExecutionPolicy", "ByPass", "-NoExit", "-Command", "& 'C:/Users/Marko/anaconda3/shell/condabin/conda-hook.ps1' ; conda activate 'C:/Users/Marko/anaconda3'"
    ]

我把上面的内容放在我的 VS Codesettings.json文件中。这会导致 Powershell 启动,就好像我-ExecutionPolicy ByPass -NoExit -Command "& 'C:\Users\Marko\anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\Marko\anaconda3' "作为参数传入它一样。这本身就可以很好地工作,但是我正在使用 Typescript 中的 VS Code 扩展,当我运行它时,它会尝试启动 Typescript 观察程序并且我收到以下错误。

> Executing task: & 'c:\Users\Marko\Source\Repos\The Spiral Language\VS Code Plugin\node_modules\.bin\tsc.cmd' -p 'c:\Users\Marko\Source\Repos\The Spiral Language\VS Code Plugin\tsconfig.json' --watch <

At line:1 char:113
+ ... k.ps1' ; conda activate 'C:/Users/Marko/anaconda3' -Command & 'c:\Use ...
+                                                                 ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed

当 PS 在没有激活 Anaconda 的参数的情况下启动时,这可以正常工作。是否可以调整我的设置以便 Anaconda 和 TS watcher 都可以启动?

标签: powershellvisual-studio-code

解决方案


在这里查看答案。只需运行conda init即可设置 Anaconda 环境在 Powershell 启动时初始化。


推荐阅读