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

Debugging fails when using a pipenv environment that gets activated with pipenv shell #4203

Closed
DonJayamanne opened this issue Jan 29, 2019 · 13 comments
Assignees
Labels
area-debugging area-terminal bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release verified Verification succeeded
Milestone

Comments

@DonJayamanne
Copy link

DonJayamanne commented Jan 29, 2019

microsoft/vscode#67692

@DonJayamanne DonJayamanne self-assigned this Jan 29, 2019
@Adanteh
Copy link

Adanteh commented Jan 30, 2019

Got this issue since today. Was perfectly fine before.

PS <path> pipenv shell
Loading .env environment variables…
Launching subshell in virtual environment…
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

is all it does when I open up debugging.

@DonJayamanne
Copy link
Author

Temporary work around

  • Go into settings (workspace settings, .vscode/settings.json)
  • Add the following:
    "python.terminal.activateEnvironment": false,

@Handsome2734
Copy link

Handsome2734 commented Jan 31, 2019

Temporary work around

  • Go into settings (workspace settings, .vscode/settings.json)
  • Add the following:
    "python.terminal.activateEnvironment": false,

This works for the first time. But the issue still happens after "Restart" debugger.
debug console after Restart
And I think I heard a beep after I clicked Restart...

@JoBrad
Copy link

JoBrad commented Jan 31, 2019

I just started having this issue today, and noticed the debug command was being cut off. Adding the python.terminal.activateEnvironment setting corrected this, but I can only execute the script completely - line-by-line debugging doesn't work (tried in VS Code Insiders and stable).

@powellquiring
Copy link

I changed the launch.json to the following thinking it would resolve the problem. But no luck. It would be cool if the pythonPath was specified in the launch configuration, the tool would use it and not look any harder for other solutions

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File (Integrated Terminal)",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "pythonPath": "/Users/pquiring/Envs/vpcibm-_JmKaXTb/bin/python"
    },
    {

I then added a file specific debug entry, so it had both. The file specific debug launcher worked, great! And then the current file entry started working as well. Crazy.

  "configurations": [
    {
      "name": "Python: Current File (Integrated Terminal)",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "pythonPath": "/Users/pquiring/Envs/vpcibm-_JmKaXTb/bin/python"
    },
    {
      "name": "vpn.py",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/vpn.py",
      "console": "integratedTerminal",
      "pythonPath": "/Users/pquiring/Envs/vpcibm-_JmKaXTb/bin/python"
    },

Maybe there is another bug dealing with caching as well.

@powellquiring
Copy link

This setting python.pythonPath in vscode/settings.json is coming into play as well. So my last comment is off base. If the python.pythonPath is set to a pipenv python:

~/tmp/vpcibm$ cat .vscode/settings.json
{
  "python.pythonPath": "/Users/pquiring/Envs/vpcibm-_JmKaXTb/bin/python",
  "python.linting.pylintPath": "/Users/pquiring/Envs/vpcibm-_JmKaXTb/bin/pylint"
}

Hit the debug button, debugging does not work, even if the launch config specifies the pythonPath to use, wierd, this is what I see in the Terminal window:

~/tmp/vpcibm$ pipenv shell
Loading .env environment variables…
Launching subshell in virtual environment…
 . /Users/pquiring/Envs/tmp-q5Tepqui/bin/activate
~/tmp$  . /Users/pquiring/Envs/tmp-q5Tepqui/bin/activate
(tmp) ~/tmp$

If you happen to have python installed somewhere else you can set python.pythonPath to that location, and initialize the launch configuration to the FQN of the pipenv python. If you don't have another copy of python handy then create one:

~/tmp/vpcibm$ cp -r /Users/pquiring/Envs/vpcibm-_JmKaXTb /tmp/pythonbin
~/tmp/vpcibm$ cat .vscode/settings.json
{
  "python.pythonPath": "/tmp/pythonbin",
  "python.linting.pylintPath": "/Users/pquiring/Envs/vpcibm-_JmKaXTb/bin/pylint"
}
~/tmp/vpcibm$ cat .vscode/launch.json
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",

  "configurations": [
    {
      "name": "Python: Current File (Integrated Terminal)",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "pythonPath": "/Users/pquiring/Envs/vpcibm-_JmKaXTb/bin/python"
    },

@bsandrow
Copy link

bsandrow commented Feb 7, 2019

For the issues that I'm having with this, it seems like it runs pipenv shell, and then does not wait to send the command to start the program w/ debugger. The issue here is that pipenv shell launches a completely new $SHELL, and then either doesn't get any of the input or just gets the tail end of the input data (in my case just gets "--noreload --nothreading" -- starting Django server in debugger).

Seems to me like what needs to happen is that pipenv shell needs to finish running and the new shell has to be fully initialized before VS Code can send the command to start the program in the debugger to the shell.

@DonJayamanne DonJayamanne removed the P0 label Feb 7, 2019
@ashja99
Copy link

ashja99 commented Feb 8, 2019

My issues with this also seem to involve Powershell (and one of examples someone provided above also appears to be in Powershell). If I switch to Command Prompt as my default terminal it works fine. Although if I keep using Powershell and set "python.terminal.activateEnvironment": false as someone said above, it also works. Not sure how/why those are related......

@DonJayamanne DonJayamanne removed this from the 2019, week 9 - Feb Sprint 5 milestone Mar 13, 2019
@DonJayamanne DonJayamanne changed the title Debugging fails when using a pipenv environment Debugging fails when using a pipenv environment that gets activated with pipenv shell Apr 4, 2019
@DonJayamanne
Copy link
Author

Prescribed solution

#5664

@akrizs
Copy link

akrizs commented Oct 20, 2019

having similar issues, sorry for popping this one to the top, but my issue seems to be that vscode starts the debug session with pipenv and if i press stop or restart then it spawns a new terminal with the same environment again, not shutting down the other instances, after a while i get the error that there are too many files open inside the environment and it wont work, sometimes it is like vscode is not running the entire command at once and rather splitting it into 3 different commands,
Im running a debug on a flask environment.

@DonJayamanne DonJayamanne mentioned this issue Oct 24, 2019
24 tasks
@luabud luabud removed important Issue identified as high-priority needs upstream fix labels Mar 11, 2020
@ghost ghost added triage-needed Needs assignment to the proper sub-team labels Mar 11, 2020
@luabud luabud added needs PR and removed triage-needed Needs assignment to the proper sub-team labels Mar 11, 2020
@DonJayamanne
Copy link
Author

We reverted old implementation #4394

@GBrachetta
Copy link

In my case, "python.terminal.activateEnvironment": false doesn't prevent pipenv from starting a new shell.
My workaround is to temporarily rename Pipfile before running the debugger, and that's the only way to get it working as far as I can tell.
I'd love to know if the launch.json file could be tweaked to sort this issue more elegantly!

@karrtikr karrtikr added this to the October 2021 milestone Oct 22, 2021
@karrtikr
Copy link

Closing as we no longer use pipenv shell command: #10611 (comment)

@karrtikr karrtikr added the verified Verification succeeded label Oct 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging area-terminal bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release verified Verification succeeded
Projects
None yet
Development

No branches or pull requests