microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.26k stars 1.15k forks source link

`Connection got disposed` error after selecting conda environment #6483

Closed rrmistry closed 5 years ago

rrmistry commented 5 years ago

I get the following error when selecting my conda environment in VS Code:

PythonConnectionGotDisposed

Snippet of the error output:

[Error - 11:16:30 AM] Server initialization failed.
Error: Connection got disposed.
    at Object.dispose (C:\Users\mistr\.vscode\extensions\ms-python.python-2019.6.22090\out\client\extension.js:1:116994)
    at Object.dispose (C:\Users\mistr\.vscode\extensions\ms-python.python-2019.6.22090\out\client\extension.js:1:198289)
    at module.exports.t.BaseLanguageClient.stop._connectionPromise.state.g.Stopping._onStop._onStop.resolveConnection.then.e.shutdown.then (C:\Users\mistr\.vscode\extensions\ms-python.python-2019.6.22090\out\client\extension.js:1:195239)

The correct conda environment is not activated so this causes issues when running python notebooks through the integrated IPython Kernel.

Environment data

Expected behaviour

No error during conda environment activation. Language server initializes with the proper conda environment.

Actual behaviour

Conda environment is not activated successfully. Language server using base conda environment.

Steps to reproduce:

  1. Install Miniconda as found here: https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
  2. Create conda environment using conda env update --name <your-env> --file environment.yml Where environment.yml has the form:

    # Load Packages From Following
    channels:
    - conda-forge
    - defaults
    
    # Define Environment Dependencies
    dependencies:
    - python=3.6.5
    - pip

Workaround

Manually create an environment activation file under <your-env>/Scripts/activate.bat that VS Code triggers in the background.

For me I had to create it under D:\Miniconda3\envs\righteous-pulse\Scripts\activate.bat with the file contents:

"D:\Miniconda3\Scripts\activate.bat" righteous-pulse

which executes "activate.bat" found in the base conda environment.

Possible related issue

rrmistry commented 5 years ago

I was able to isolate the problem to the following code location: https://github.com/microsoft/vscode-python/blob/66de533a2a72276f16d82d6d4494cebee47e63bd/src/client/common/terminal/environmentActivationProviders/commandPrompt.ts#L40-L48 where the extension is trying to find the appropriate activate.bat file in the sequence of most likely locations. But I think there may have been a recent change in conda which no longer creates this file. I haven't been able to confirm this yet.

rrmistry commented 5 years ago

Looks like re-installing anaconda fixed the issue.

The new VS Code python terminal initialization is:

D:\repos\VSTS\righteous-ai\righteous-pulse>D:/Anaconda3/Scripts/activate

(base) D:\repos\VSTS\righteous-ai\righteous-pulse>conda activate righteous-pulse

(righteous-pulse) D:\repos\VSTS\righteous-ai\righteous-pulse>

Curious as to how this occurred in the first place.

I'll close this issue now. My apologies for any confusion.