Skip to content
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

wrong kernel loads in python interactive #2856

Closed
dschneiderch opened this issue Oct 18, 2019 · 6 comments
Closed

wrong kernel loads in python interactive #2856

dschneiderch opened this issue Oct 18, 2019 · 6 comments

Comments

@dschneiderch
Copy link

I can't choose the conda kernels. This has always been hit or miss (there was a previous thread I was part of that I couldn't find) but now no matter what it always launches the same kernel.

vscode-kernel-issue

Environment data

  • VS Code version: 1.39.1
  • Extension version 2019.10.41019 (8 October 2019)
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): miniconda, python 3.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Jedi not check

Expected behaviour

I select the conda kernel from the bottom left or from ctrl+shift+p and then launch conda kernel

Actual behaviour

always launches same kernel "plantcv"

Steps to reproduce:

select any kernel from any conda environment

Logs

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

User belongs to experiment group 'ShowPlayIcon - start'
Starting Microsoft Python language server.
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> py -3.7 -c "import sys;print(sys.executable)"
> py -3.6 -c "import sys;print(sys.executable)"
> py -3 -c "import sys;print(sys.executable)"
> py -2 -c "import sys;print(sys.executable)"
> ~\Miniconda3\envs\testenvironment\python.exe -c "import sys;print(sys.executable)"
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat info --json
> ~\AppData\Local\Microsoft\WindowsApps\python.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
> ~\AppData\Local\Microsoft\WindowsApps\python.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
> ~\AppData\Local\Microsoft\WindowsApps\python3.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
> ~\AppData\Local\Microsoft\WindowsApps\python3.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat info --json
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat --version
> ~\Miniconda3\envs\testenvironment\python.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\normalizeForInterpreter.py "from plantcv import plantcv as pcv"
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\testenvironment\python.exe -m notebook --version
> ~\Miniconda3\envs\testenvironment\python.exe -m notebook --version
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter notebook --version
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> C:\Python27\python.exe -m jupyter notebook --version
> C:\Python27\python.exe -m jupyter notebook --version
> C:\Python27\python.exe -c "import jupyter"
> C:\Python27\python.exe -c "import jupyter"
> ~\Miniconda3\envs\testenvironment\python.exe -m notebook --version
> ~\Miniconda3\envs\testenvironment\python.exe -m notebook --version
> C:\Python27\python.exe -m notebook --version
> C:\Python27\python.exe -m notebook --version
> C:\Python27\python.exe -c "import notebook"
> C:\Python27\python.exe -c "import notebook"
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> ~\Miniconda3\envs\plantcv\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\plantcv\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\plantcv\python.exe -m notebook --version
> ~\Miniconda3\envs\plantcv\python.exe -m notebook --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m notebook --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m notebook --version
> ~\Miniconda3\python.exe -m jupyter notebook --version
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -m kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -m kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -c "import kernelspec"
> ~\Miniconda3\envs\testenvironment\python.exe -c "import kernelspec"
> ~\Miniconda3\python.exe -m jupyter kernelspec --version
> C:\Python27\python.exe -m jupyter kernelspec --version
> C:\Python27\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\plantcv\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\plantcv\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -m jupyter kernelspec --version
> C:\Python27\python.exe -c "import jupyter"
> C:\Python27\python.exe -c "import jupyter"
> C:\Python27\python.exe -m kernelspec --version
> C:\Python27\python.exe -m kernelspec --version
> ~\Miniconda3\envs\plantcv\python.exe -m kernelspec --version
> ~\Miniconda3\envs\plantcv\python.exe -m kernelspec --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m kernelspec --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -m kernelspec --version
> ~\Miniconda3\envs\testenvironment\python.exe -m kernelspec --version
> C:\Python27\python.exe -c "import kernelspec"
> C:\Python27\python.exe -c "import kernelspec"
> ~\Miniconda3\envs\plantcv\python.exe -c "import kernelspec"
> ~\Miniconda3\envs\plantcv\python.exe -c "import kernelspec"
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -c "import kernelspec"
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -c "import kernelspec"
> ~\Miniconda3\envs\testenvironment\python.exe -c "import kernelspec"
> ~\Miniconda3\envs\testenvironment\python.exe -c "import kernelspec"
> ~\Miniconda3\python.exe -m jupyter kernelspec list
> ~\Miniconda3\python.exe -m jupyter kernelspec list
> ~\Miniconda3\python.exe -m jupyter notebook --no-browser --notebook-dir=C:\Users\dominikschneider\AppData\Local\Temp\7e4576ef-5b39-40cc-b72f-485cb60700eb --config=C:\Users\dominikschneider\AppData\Local\Temp\7e4576ef-5b39-40cc-b72f-485cb60700eb\jupyter_notebook_config.py --NotebookApp.iopub_data_rate_limit=10000000000.0
> ~\Miniconda3\python.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\datascience\getServerInfo.py
> ~\Miniconda3\python.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\datascience\getServerInfo.py
> ~\Miniconda3\envs\testenvironment\python.exe -m ipykernel --version
> ~\Miniconda3\envs\testenvironment\python.exe -m ipykernel --version
> ~\Miniconda3\python.exe -m ipykernel --version
> C:\Python27\python.exe -m ipykernel --version
> C:\Python27\python.exe -m ipykernel --version
> ~\Miniconda3\envs\plantcv\python.exe -m ipykernel --version
> ~\Miniconda3\envs\plantcv\python.exe -m ipykernel --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m ipykernel --version
> ~\Miniconda3\envs\plantcvmanuscript\python.exe -m ipykernel --version
> ~\Miniconda3\envs\testenvironment\python.exe -m ipykernel --version
> ~\Miniconda3\envs\testenvironment\python.exe -m ipykernel --version
> C:\Python27\python.exe -c "import ipykernel"
> C:\Python27\python.exe -c "import ipykernel"
> ~\Miniconda3\python.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
> ~\Miniconda3\python.exe c:\Users\dominikschneider\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
> ~\Miniconda3\python.exe -m pip --version
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> c:/Users/dominikschneider/Miniconda3/Scripts/activate.bat env list
> ~\Miniconda3\python.exe -m jupyter notebook --version

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

vscode-kernel-issue.txt

@rchiodo
Copy link
Contributor

rchiodo commented Oct 18, 2019

This is because we can't start jupyter in your other environments. We fall back to searching through all of them if we can't start on the one you started with.

You can see that with this here:

[Extension Host] Info Python Extension: 2019-10-17 17:22:38: > ~\Miniconda3\envs\testenvironment\python.exe -m jupyter notebook --version
console.ts:137 [Extension Host] Warn Python Extension: 2019-10-17 17:22:38: Traceback (most recent call last):
  File "C:\Users\dominikschneider\Miniconda3\envs\testenvironment\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\dominikschneider\Miniconda3\envs\testenvironment\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\dominikschneider\Miniconda3\envs\testenvironment\lib\site-packages\jupyter.py", line 4, in <module>
    main()
  File "C:\Users\dominikschneider\Miniconda3\envs\testenvironment\lib\site-packages\jupyter_core\command.py", line 230, in main
    command = _jupyter_abspath(subcommand)
  File "C:\Users\dominikschneider\Miniconda3\envs\testenvironment\lib\site-packages\jupyter_core\command.py", line 133, in _jupyter_abspath
    'Jupyter command `{}` not found.'.format(jupyter_subcommand)
Exception: Jupyter command `jupyter-notebook` not found.

This means that the testenvironment does not have jupyter installed (or at least findable).

@dschneiderch
Copy link
Author

strange, because it works fine from anaconda prompt.

(testenvironment) C:\Users\dominikschneider\Documents\phenomics\GoldStandard2>jupyter notebook
[I 09:15:30.826 NotebookApp] [nb_conda_kernels] enabled, 4 kernels found
[I 09:15:31.503 NotebookApp] [nb_conda] enabled
[I 09:15:31.505 NotebookApp] Serving notebooks from local directory: C:\Users\dominikschneider\Documents\phenomics\GoldStandard2
[I 09:15:31.505 NotebookApp] The Jupyter Notebook is running at:
[I 09:15:31.506 NotebookApp] http://localhost:8888/?token=d6b025b2683ec6936da3e4fba43ba594c1b792776ab55e12
[I 09:15:31.506 NotebookApp]  or http://127.0.0.1:8888/?token=d6b025b2683ec6936da3e4fba43ba594c1b792776ab55e12
[I 09:15:31.507 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 09:15:31.617 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/dominikschneider/AppData/Roaming/jupyter/runtime/nbserver-26192-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=d6b025b2683ec6936da3e4fba43ba594c1b792776ab55e12
     or http://127.0.0.1:8888/?token=d6b025b2683ec6936da3e4fba43ba594c1b792776ab55e12

@rchiodo
Copy link
Contributor

rchiodo commented Oct 18, 2019

Yeah from your log it looks we're unable to activate any of the conda environments. This may be related to:
microsoft/vscode-python#7548

@dschneiderch
Copy link
Author

so still a mystery....

@greazer
Copy link
Contributor

greazer commented Oct 18, 2019

Dupe of microsoft/vscode-python#5344

@greazer greazer closed this as completed Oct 18, 2019
@dschneiderch
Copy link
Author

dschneiderch commented Oct 21, 2019

This is a conda problem not specific to vscode. The following is a reproducible resolution on my computer (windows 10).
jupyter kernelspec list needs to show the kernels for vscode (and other 3rd party apps I tried) to load the environment. I think conda is supposed to automatically create kernels for each environment if nb_conda_kernels is installed in the root env but that doesn't seem to happen. So after creating an env, make sure ipykernel and notebook are installed and then MANUALLY install the kernel per the docs https://ipython.readthedocs.io/en/latest/install/kernel_install.html#kernels-for-different-environments

The catch is that you must specify a unique kernel name otherwise the kernel is called python3 and overwrites the python3 kernel that already exists (either from the root env, or from the first custom env you created a kernel for if you have more than 1).

conda activate myenv
conda install ipykernel notebook
python -m ipykernel install --user --name <myenv>
conda deactivate
conda activate myenv

I had to restart vscode twice to get it to find my new kernel.

I hope this helps others because it was a royal PIA. I also hope this gets more robust from anaconda or from the proposals in microsoft/vscode-python#5344

I pieced this together from these sources, in particular the first
anaconda/nb_conda_kernels#112 (comment)
https://stackoverflow.com/questions/56435806/jupyter-kernelspec-list-command-doesnt-find-all-kernels
https://stackoverflow.com/questions/39604271/conda-environments-not-showing-up-in-jupyter-notebook/44786736#44786736

@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants