Debug Cell does not work with PowerShell Core on Linux
See original GitHub issueBug: Notebook Editor, Interactive Window, Editor cells
Steps to cause the bug to occur
- Install latest PowerShell core and set it as your default shell on Linux.
- Open any Python script
- Add #%% line before any code block
- Press Debug Cell
Actual behavior
It should install debugpy if necessary and then start the debugging session.
Expected behavior
It fails to install debugpy, giving the following error: Pip module debugpy is required for debugging cells. You will need to install it to debug cells.
Bug Information & Fix
After looking at the vscode-python source, I was able to figure out the cause of the bug. To figure out whether debugpy is installed (and to install debugpy), you use the !
operator in Jupyter to execute a shell command (see the following example which uses the pythonShellCommand variable here). This shell command is built as "{sys.executable}" -c "{some python code}"
. This evaluates to "/usr/bin/python" -c "{some python code}"
on my machine. While that is a valid bash command, it’s not actually a valid PowerShell command (see the output below for an example). For PowerShell, we need to prepend this command with an ampersand (see the output below for a working example).
PS /home/nimas> "/usr/bin/python" -c "print 'hi'"
ParserError:
Line |
1 | "/usr/bin/python" -c "print 'hi'"
| ~~
| Unexpected token '-c' in expression or statement.
PS /home/nimas> & "/usr/bin/python" -c "print 'hi'"
hi
Another solution could be to use os.system
instead of the !
operator in Juypter, as os.system
defaults to using /bin/sh
on Linux.
Your Jupyter and/or Python environment
Please provide as much info as you readily know
- Jupyter server running: Local and Remote
- Extension version: 2020.8.109390
- VS Code version: 1.50.0-insider
- Setting python.jediEnabled: false
- Setting python.languageServer: Pylance
- Python and/or Anaconda version: 3.7.7 (conda 4.8.3)
- OS: Windows | Mac | Linux (distro): Linux
- Virtual environment: Have tested with Conda and Pipenv
Python Output
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - control'
User belongs to experiment group 'CustomEditorSupport - control'
User belongs to experiment group 'pythonaa'
Error 2020-09-17 13:04:54: Failed to register VS Code Notebook API [TypeError: this.notebook.registerNotebookOutputRenderer is not a function
at u.registerNotebookOutputRenderer (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:54:512718)
at v.activate (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:631732)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async Promise.all (index 30)
at async Promise.all (index 0)
at async v.activate (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:295299)]
> conda --version
> pyenv root
> python3.7 ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
Error 2020-09-17 13:04:55: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://dev-container+7b22686f737450617468223a222f686f6d652f6e696d61732f446f63756d656e74732f6264692d6e65772d636f6d7072657373696f6e222c2273657474696e6773223a7b22686f7374223a227373683a2f2f6e696d6173406c6f63616c686f73743a32323031227d7d/root/.config/Code - Insiders/User/settings.json' (EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open '/root/.config/Code - Insiders/User/settings.json')
at _handleError (/root/.vscode-server-insiders/bin/9e505675670d65138405321a60b0df4ddec28799/out/vs/server/remoteExtensionHostProcess.js:744:165)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async v.readText (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:1:495755)
at async p.doesFileNeedToBeFixed (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:953520)
at async /root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952647
at async Promise.all (index 0)
at async p.getFilesToBeFixed (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952593)
at async p.updateTestSettings (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:952220)] {
code: 'FileNotFound',
name: 'EntryNotFound (FileSystemError)'
}
> conda info --json
> conda info --json
Python interpreter path: /opt/conda/bin/python
Starting Pylance language server.
> conda env list
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py jupyter kernelspec --version
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> /opt/conda/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
Error 2020-09-17 13:05:08: Failed to install debugpy
Error 2020-09-17 13:05:08: DataScience Error [i [Error]: Pip module debugpy is required for debugging cells. You will need to install it to debug cells.
at E.installDebugger (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:424275)
at async E.promptToInstallDebugger (/root/.vscode-server-insiders/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:423663)]
Microsoft Data Science for VS Code Engineering Team: @rchiodo, @IanMatthewHuff, @DavidKutu, @DonJayamanne, @greazer, @joyceerhl
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (9 by maintainers)
Top GitHub Comments
Yes, I figured that, hence
Or does this code predate the usage of the shipped debugger in DS code.
& I have seen some issues where we were meant to use the one that was shipped. I think we did end up using the one we have shipped, however forgot to remove this check.I"m proposing we remove this check when debugging with local connections. We could always do this as an experiment.
I don’t think this is an issue anymore. As we don’t use
!
to install the packages. If the problem persists, please feel free to re-open this issue.