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.

Option "execute in file dir" ignored when use play button "debug python file in terminal"

See original GitHub issue

Environment data

  • VS Code version: 1.61.0
  • Extension version: 2021.10.1317843341
  • OS and version: 10.0.19043.1237
  • Python version: 3.8.8 Anaconda
  • Type of virtual environment used: conda
  • Value of the python.languageServer setting: default

Expected behaviour

When debugging python file in terminal, it should use the option to “execute the file in the file’s directory, instead of the current open folder” (setting "python.terminal.executeInFileDir": true)

It is ok when choose “run python file in terminal”. It should do the same when debugging.

gif001

Actual behaviour

“Debug python file in terminal” (with the same “play button” used to “run python file in terminal”) ignores the setting "python.terminal.executeInFileDir": true

gif002

Steps to reproduce:

Try to “debug python file in the terminal” with the same “play button” used to “run python file in terminal”.

It leads to error specially when leading with local files in debugging, which worked fine when running.

See bellow running and debugging the same file, in the same folder.

gif003

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
karthiknadigcommented, Oct 8, 2021

@Diogo-Rossi As a work around you can add debug configuration to launch json:

        {
            "name": "Python: Debug in file dir",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${fileDirname}",
            "purpose": ["debug-in-terminal"]
        }
1reaction
rongrothcommented, Nov 29, 2021

@Diogo-Rossi As a work around you can add debug configuration to launch json:

        {
            "name": "Python: Debug in file dir",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${fileDirname}",
            "purpose": ["debug-in-terminal"]
        }

I had tried everything that I could find via Google to get this to work. I was about to write that it didn’t work for me, but I realized that there was the additional “purpose” line. I added that and it now seems to be working - my print(os.getcwd()) is for the file’s directory now when I do debug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging configurations for Python apps in Visual Studio Code
To initialize debug configurations, first select the Run view in the sidebar: ... Two common options are to use the Python File configuration...
Read more >
[BUG] Debugging with purpose ignored in user/workspace ...
It would be great to configure run/debug button for loose files: If file is in workspace but there is no launch.json : use...
Read more >
Debugger Not Stopping at Breakpoints in VS Code for Python
Right-click VS Code icon, choose "Run as Administrator. ... breakpoints on any Python file, even outside of your Python project's directory; ...
Read more >
Python in VSCode: Running and Debugging
How to use Python in VSCode. Learn how to run and debug your code, use VSCode with a Python virtualenv, and select the...
Read more >
Command line usage — Coverage.py 6.4.4 documentation
run – Run a Python program and collect execution data. ... Any command can use a configuration file by specifying it with the...
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