question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selecting Python interpreter in conda environment has no effect

See original GitHub issue

Environment data

  • VS Code version: 1.52.1 (user setup) Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523
  • Jupyter Extension version: v2020.12.414227025
  • Python Extension version: v2020.12.424452561
  • OS: Windows 10, Version 10.0.17763 Build 17763
  • Anaconda 3.7.7 vs. 3.9.1
  • Type of virtual environment used: conda
  • Jupyter server running: Local

Version: 1.52.1 (user setup) Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523 Date: 2020-12-16T16:34:46.910Z Electron: 9.3.5 Chrome: 83.0.4103.122 Node.js: 12.14.1 V8: 8.3.110.13-electron.0 OS: Windows_NT x64 10.0.17763

Expected behaviour

Selecting a Python interpreter in the Jupyter extension’s interpreter drop-down menu (or using command palette) should result in that interpreter being used in the Jupyter notebook.

Actual behaviour

Selecting the Python 3.9.1 interpreter in a conda environment from the drop-down menu (or using command palette) seems to have no effect. It is stuck on the one in the base conda environment (3.7.7 in my case).

Steps to reproduce:

Open an .ipynb file as Jupyter notebook, switch Python interpreters. Print sys.version

import sys
print(sys.version)

Wrong version displayed, as shown in this screenshot:

vscode-jupyter-python-interpreter

Logs

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

> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py jupyter kernelspec --version
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> ~\Anaconda3\envs\sutokura\python.exe -c "import os;print(os.path.realpath("C:\\Users\\jeaco\\AppData\\Roaming\\jupyter\\kernels"))"
> ~\Anaconda3\envs\sutokura\python.exe -c "import os;print(os.path.realpath("C:\\Users\\jeaco\\AppData\\Roaming\\jupyter\\kernels"))"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
Started kernel Python 3
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
Started kernel Python 3
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\pdtable-dev\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\e2d\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
Error 2021-01-04 14:03:00: Install Missing Dependencies, Class name = f, completed in 867ms, has a falsy return value, Return Value: undefined [Error: Command failed: C:/Users/jeaco/Anaconda3/Scripts/activate && conda activate dash && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\jeaco\.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\pyvsc-run-isolated.py c:/Users/jeaco/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/printEnvVariables.py
Traceback (most recent call last):
  File "c:\Users\jeaco\.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\pyvsc-run-isolated.py", line 30, in <module>
    runpy.run_path(module, run_name="__main__")
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\runpy.py", line 252, in run_path
    return _run_module_code(code, init_globals, run_name, path_name)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "c:/Users/jeaco/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/printEnvVariables.py", line 7, in <module>
    print(json.dumps(dict(os.environ)))
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\json\__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\json\encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\json\encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd8 in position 26: invalid continuation byte

	at ChildProcess.exithandler (child_process.js:304:12)
	at ChildProcess.emit (events.js:223:5)
	at maybeClose (internal/child_process.js:1021:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)] {
  killed: false,
  code: 1,
  signal: null,
  cmd: "C:/Users/jeaco/Anaconda3/Scripts/activate && conda activate dash && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\\Users\\jeaco\\.vscode\\extensions\\ms-python.python-2020.12.424452561\\pythonFiles\\pyvsc-run-isolated.py c:/Users/jeaco/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/printEnvVariables.py",
  vslsStack: [ CallSite {}, CallSite {}, CallSite {}, CallSite {} ]
}
Error 2021-01-04 14:03:05: Install Missing Dependencies, Class name = f, completed in 859ms, has a falsy return value, Return Value: undefined [Error: Command failed: C:/Users/jeaco/Anaconda3/Scripts/activate && conda activate dash && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\jeaco\.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\pyvsc-run-isolated.py c:/Users/jeaco/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/printEnvVariables.py
Traceback (most recent call last):
  File "c:\Users\jeaco\.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\pyvsc-run-isolated.py", line 30, in <module>
    runpy.run_path(module, run_name="__main__")
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\runpy.py", line 252, in run_path
    return _run_module_code(code, init_globals, run_name, path_name)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "c:/Users/jeaco/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/printEnvVariables.py", line 7, in <module>
    print(json.dumps(dict(os.environ)))
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\json\__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\json\encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Users\jeaco\Anaconda3\envs\dash\lib\json\encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd8 in position 26: invalid continuation byte

	at ChildProcess.exithandler (child_process.js:304:12)
	at ChildProcess.emit (events.js:223:5)
	at maybeClose (internal/child_process.js:1021:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)] {
  killed: false,
  code: 1,
  signal: null,
  cmd: "C:/Users/jeaco/Anaconda3/Scripts/activate && conda activate dash && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\\Users\\jeaco\\.vscode\\extensions\\ms-python.python-2020.12.424452561\\pythonFiles\\pyvsc-run-isolated.py c:/Users/jeaco/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/printEnvVariables.py",
  vslsStack: [ CallSite {}, CallSite {}, CallSite {}, CallSite {} ]
}
> ~\Anaconda3\envs\e2d\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\e2d\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
Started kernel Python 3
> ~\Anaconda3\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"
> ~\Anaconda3\envs\sutokura\python.exe c:\Users\jeaco\.vscode\extensions\ms-toolsai.jupyter-2020.12.414227025\pythonFiles\pyvsc-run-isolated.py -c "import ipykernel"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rchiodocommented, Apr 14, 2021

We have been making changes in both the python extension and the jupyter extension to fix this sort of thing lately. It all depends upon what version you had before I guess. I’ll close this issue since it seems like it resolved itself.

1reaction
rchiodocommented, Apr 9, 2021

What version is the Jupyter extension?

Additionally we’d need the ‘Jupyter’ output tab data. It should list what the command was that we ran to start the kernel.

My guess is that Python 3.9.2 64-bit (sutokora: conda) shares a kernelspec with something else and when we launch the kernel it’s finding the something else instead.

For example the kernelspec might look like this:

"python3": {
      "resource_dir": "C:\\Users\\aku91\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\ipykernel\\resources",
      "spec": {
        "argv": [
          "python",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "Python 3",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {}
      }
    }

The ‘python’ argument is ambiguous.

But we’d need the output to determine if that’s the case.

The jupyter extension version would be helpful too. We’ve made some fixes around this lately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conda environment not showing up in VS Code - Stack Overflow
in vscode press ctrl+shift+p and type python:Select Interpreter you should see all the environment there. If it does not appear create a .py ......
Read more >
Using Python environments in VS Code
To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).
Read more >
This Python interpreter is in a conda environment, but the ...
The resolve the "This Python interpreter is in a conda environment, but the environment has not been activated. Libraries may fail to load"...
Read more >
Managing environments - Conda
With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them.
Read more >
Frequently Asked Questions — Spyder 5 documentation
Here, select the option Use the following Python interpreter, and use the dropdown below to select your preferred environment. If it is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found