-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PowerShell does not support automatic activation of conda virtual environment #11638
Comments
For anyone working on this issue: If we need to run two commands in a shell, right now there is no easy way to it. We have to use sendText and provide the command string. We need a API from VS to sendCommand, otherwise we have to duplicate shell detection and shell escaping in our extension to send the two commands correctly. Although this issue is for PS only, the activation mechanism impacts any shell that we try to send the command to. |
@karthiknadig I am not very familiar with VSCode's extension development technology. But I tried to modify the file extension.js to test the command execution async getPowershellCommands(e){return[`& 'F:\\ProgramData\\Anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'F:\\ProgramData\\Anaconda3' ; conda activate ${e.toCommandArgument()}`]} Back to VSCode, it seems to work. The conda environment is automatically activated. Perhaps the path of the condabin folder can be known through conda path, making the command applicable However, it was so smooth that I doubted what I did wrong. Are there any potential problems with this?If you think this is a repeated and stupid idea, just tell me not to do this and close the issue, thank you! |
@alexzshl the right way to do this is |
Yeah conda, VSCode and Powershell is still a mess for the average programmer. Microsoft are now launching Windows Terminal. They make VSCode look easy, but it does not play nice with conda. I can run python scripts from an Anaconda shell, but not from VS Code, because hat defaults to Powershell, conda . I have seen suggestions to change the VS Code terminal to cmd, and avoid the use of powershell. |
I am having the same issue when opening a PowerShell terminal, which just tries to run "conda activate XYZ", but fails since conda is not in the path by default. Strangely it works with a cmd terminal, so I wonder why it works there, but not for PowerShell. |
We need you to set As I said in my previous comment, in the case of powershell, you have to run There are several issues that we have run into with conda, See here #5344. We even attempted using
This will give you an activated environment, and the extension will not have to try and activate every time a terminal is created. |
Does this relate to #13464? Running into it again, and Google searches landed on this issue. |
I was able to get VSCode to recognize the conda environment without running VSCode from Anaconda prompt. This worked for me: 1: Run
This allows the script created by You do get a warning that |
For those having issues getting PowerShell to drop into a conda environment correctly, the following settings work by calling the proper conda scripts when PowerShell launches. You will need to modify the paths to point to your
|
Python extension can automatically identify conda in cmd without any settings, "conda path" in settings seems useless in pwsh, I have tried many methods, the most convenient one is to use cmd directly. |
Now that |
It seems that the powershell terminal does not support automatic activation of the conda virtual environment?I am not sure if this is my problem or it is currently the case.
If we need a way to activate the conda virtual environment from the powershell terminal, I hope the following information can provide some help
Anaconda supports powershell terminal.The following is an example of the startup command provided by Anaconda:
According to the above information, I activated the conda virtual environment in the powershell terminal of VSCode
The text was updated successfully, but these errors were encountered: