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.

Debug Cell does not work with PowerShell Core on Linux

See original GitHub issue

Bug: Notebook Editor, Interactive Window, Editor cells

Steps to cause the bug to occur

  1. Install latest PowerShell core and set it as your default shell on Linux.
  2. Open any Python script
  3. Add #%% line before any code block
  4. 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:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
DonJayamannecommented, Sep 17, 2020

Maybe we’re confident enough in our shipping debugpy to assume this now though.

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.

0reactions
DonJayamannecommented, Apr 13, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use the PowerShell Debugger to Troubleshoot Scripts
When the script pauses execution, the Windows PowerShell console drops into debug mode. This special mode permits the use of certain commands.
Read more >
Running and debugging PowerShell Core scripts on macOS ...
First create a new folder and open it with VS Code. (Do not simply create a new file. An open folder is required...
Read more >
Load a PowerShell module for debugging when starting ...
The argument './InstallProvider.ps1' is not recognized as the name of a script file. Check the spelling of the name, or if a path...
Read more >
Windows PowerShell Cheat Sheet
PS may be seen as Microsoft's answer to the shells common in Unix/Linux (such ... It must be stressed here that many of...
Read more >
Attaching to PowerShell 7.1.4 from VS 2022 gives error "a ...
I am creating a PowerShell Core Module in C# with Visual Studio 2022. ... Linux Core Dump Debugging 1.0.9.31410 Enables debugging of Linux...
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