简体   繁体   English

在项目虚拟环境中启动 VScode

[英]Start VScode in projects virtual environment

I would like my VScode terminal to be in the correct virtual environment as soon as I open the project folder.我希望我的 VScode 终端在打开项目文件夹后立即处于正确的虚拟环境中。 At the moment I always have to get out of my conda environment and into the projects environment.目前,我总是必须离开我的 conda 环境并进入项目环境。 I would like a script that runs:我想要一个运行的脚本:

conda deactivate
source ~/path/to/activate

as soon as I open the project folder in VScode.只要我在 VScode 中打开项目文件夹。 Cheers!干杯!

Normally speaking, once you choose the interpreter, it will be recorded in workspace cache.通常来说,一旦你选择了解释器,它就会被记录在工作空间缓存中。

You can manually set your interpreter in Workspace Settings.json :您可以在Workspace Settings.json中手动设置您的解释器:

"python.pythonPath": "<the full path to your interpreter>"

then every time you reopen the project, the environment will automatically redirect to the chosen one and load it.然后每次重新打开项目时,环境都会自动重定向到选择的项目并加载它。

[UPDATE] [更新]

Turn to the directory C:\Users\name\Documents\WindowsPowerShell and open profile.ps1 , you will find some code that can initialize conda environment, so every time you open project with powershell, the conda environment will also be activated, there're two solutions:转到目录C:\Users\name\Documents\WindowsPowerShell并打开profile.ps1 ,你会发现一些可以初始化 conda 环境的代码,所以每次使用 powershell 打开项目时,conda 环境也会被激活,那里'重新两个解决方案:

1.Comment the code in profile.ps1; 1.注释profile.ps1中的代码;

2.Choose cmd as your default Terminal in VS Code. 2.在 VS Code 中选择 cmd 作为默认终端。

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

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