microsoft / vscode-python

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

Extension doesn't activate conda environment #6918

Closed cristi-neagu closed 5 years ago

cristi-neagu commented 5 years ago

Hello,

It used to be the case that when i ran a script in debug within a conda environment, the first time it would fail with the error ImportError: DLL load failed: The specified module could not be found. Right after the debugger would end, the console would run conda activate to activate the environment, and running the script again would function correctly.

But that isn't happening any longer. A few days ago i updated conda (using the prompt), and something went wrong and Anaconda shortcuts disappeared from the Start Menu. I reinstalled conda in the exact same location, and it is working fine. Jupyter Notebook launches correctly, runs ok, no problems. But now VS Code doesn't activate the environment any longer. It does see the environments and i can select them. It does seem to use the selected environment, as it complains about pylint not being installed if i switch to an environment with no pylint.

I tried adding the conda folder to the path. This actually worked for 1 session of using VS Code, and now it doesn't work any longer, with me not changing absolutely anything. I tried initializing cmd.exe for use with conda, so now i can type conda activate in the Python debug terminal and it does activate the terminal and the script can run. But VS Code is still not doing it automatically.

Also, when i installed conda, i did select the option that makes it visible to VS Code. I forget the actual wording, but it was on the same screen as the "add to path" option.

At this point i don't even know if this is a conda issue, a VS Code issue, or a Python extension issue. Any ideas are welcome.

Thank you.

DonJayamanne commented 5 years ago

Thanks for reporting this issue. However to help you we need more information, please could you take the Time to fill in the issue template.

Wenzil commented 5 years ago

I have the same (or a very similar) issue.

Environment data

Expected behaviour

VS Code picks up the Conda environment specified in my python.pythonPath folder setting when starting the Python Interactive session, e.g. /Users/<redacted>/anaconda3/envs/<my_env>/bin/python

Actual behaviour

VS Code only picks up the base Conda environment:

Jupyter Server URI: http://localhost:8889/?token=<redacted>
Python version:
3.7.3 (default, Mar 27 2019, 16:54:48) \n[Clang 4.0.1 (tags/RELEASE_401/final)]
(6, 0, 0)
/Users/<redacted>/anaconda3/bin/python

Steps to reproduce:

  1. Create a multi-root workspace
  2. Create a basic my_env conda environment (from an external terminal shell)
    conda create -n my_env python pylint pyface
  3. With the Python: Select Interpreter command, for some folder in the multi-root workspace, select the my_env conda environment
  4. Create a single-cell .py file in the folder
    #%%
    import pyface
  5. Within the file, click on Run Cell to start a Python Interactive session
  6. Notice the environment being picked up is not matching the one selected in step 3.

Logs

Output for cell [1] in the Python Interactive window

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
 in 
----> 1 import pyface

ModuleNotFoundError: No module named 'pyface'

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

> conda env list
> conda info --json
> ~/anaconda3/bin/python -m jupyter notebook --version
> ~/anaconda3/bin/python -m jupyter kernelspec --version
> ~/anaconda3/bin/python -m jupyter kernelspec list
> ~/anaconda3/bin/python -m jupyter kernelspec list
> ~/anaconda3/bin/python -m jupyter notebook --no-browser --notebook-dir=/var/folders/q5/pspsf7q94qlbhdn41jqr6_080000gn/T/da9e7816-c209-412e-bfa5-86fa1de7eab3 --config=/var/folders/q5/pspsf7q94qlbhdn41jqr6_080000gn/T/da9e7816-c209-412e-bfa5-86fa1de7eab3/jupyter_notebook_config.py --NotebookApp.iopub_data_rate_limit=10000000000.0
> ~/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2019.8.30787/pythonFiles/datascience/getServerInfo.py
> ~/anaconda3/bin/python ~/.vscode/extensions/ms-python.python-2019.8.30787/pythonFiles/datascience/getServerInfo.py
> ~/anaconda3/bin/python -m ipykernel --version
Wenzil commented 5 years ago

I found https://github.com/microsoft/vscode-python/issues/3123 to be the culprit. My workaround is to move up my project to be the first folder in my multi-root workspace

ericsnowcurrently commented 5 years ago

@cristi-neagu, does that workaround help you?

cristi-neagu commented 5 years ago

Hello,

I apologise for not responding to this earlier. Limited time and all that. I shall respond tomorrow with the requested template.

@ericsnowcurrently Unfortunately no, since it's not a multi-root workspace. It's just one folder. Like i said in my initial post, i don't think this is something caused by VS Code or by the Python extension. Something broke somewhere in my setup, it's just that i don't even know where to start. In any case, i shall post that template tomorrow.

Thank you.

ronglums commented 5 years ago

Looks like the original issues isn't data science specific. Removing the label.

kimadeline commented 5 years ago

Duplicate of https://github.com/microsoft/vscode-python/issues/7696