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

Cannot execute the python process in Debug when changing the working directory #195

Closed
DonJayamanne opened this issue Nov 14, 2017 · 16 comments
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@DonJayamanne
Copy link

From @alexmolodchikov on October 5, 2017 3:3

Environment data

VS Code version: 1.16.1
Python Extension version: 0.7.0
Python Version: 3.6.2
OS and version: macOS High Sierra 10.13

Actual behavior

Error: spawn /Users/aamolodc/cloudtrek/the-dentist/env/bin/python ENOENT
Failed to launch the Python process, please validate the path
"cwd": "/Users/aamolodc/cloudtrek/the-dentist/the-dentist/"

Expected behavior

Execution of the Python process.
(
runs normally when working directory is set to:
"cwd": "/Users/aamolodc/cloudtrek/the-dentist/"
)

Steps to reproduce:

pythonPath seems to have no effect somehow?

set launch.json to this:

        {
            "name": "IDP-Web-Interface",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "/Users/aamolodc/cloudtrek/the-dentist/the_dentist/run_web.py",
            "cwd": "/Users/aamolodc/cloudtrek/the-dentist/the-dentist/",
            "args": [
                "--config" , "the_dentist/config.yml"
            ],
            "env": {
                "PYTHONUNBUFFERED":"1", 
                "PYTHONPATH": "/Users/aamolodc/cloudtrek/the-dentist/the-dentist"
            },
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },

Logs

Output from Python output panel

Error: spawn /Users/aamolodc/cloudtrek/the-dentist/env/bin/python ENOENT
Output from Console window (Help->Developer Tools menu)

/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28 Failed to launch the Python Process, please validate the path '/Users/aamolodc/cloudtrek/the-dentist/env/bin/python'

  | e.doShow | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
-- | -- | -- | --
  | e.show | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | (anonymous) | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:29
  | v | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | enter | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | _run | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | _chainedError | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | n | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | then | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | enter | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | _run | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | _setCompleteValue | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | v | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | enter | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | _run | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | _error | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | (anonymous) | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | e.dispatch | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | e.handleData | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | (anonymous) | @ | /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:28
  | emitOne | @ | events.js:96
  | emit | @ | events.js:191
  | readableAddChunk | @ | _stream_readable.js:178
  | Readable.push | @ | _stream_readable.js:136
  | onread | @ | net.js:560

Copied from original issue: DonJayamanne/pythonVSCode#1274

@DonJayamanne
Copy link
Author

Please ensure the path /Users/aamolodc/cloudtrek/the-dentist/env/bin/python exists and the case is correct.

Also, you seem to have duplicated the the-dentist in the following sections of the settings, is that correct.

            "program": "/Users/aamolodc/cloudtrek/the-dentist/the_dentist/run_web.py",
            "cwd": "/Users/aamolodc/cloudtrek/the-dentist/the-dentist/",

@DonJayamanne
Copy link
Author

From @alexmolodchikov on October 5, 2017 5:43

Hi Don,
Thank you for very quick response. I appreciate your time.

Please ensure the path /Users/aamolodc/cloudtrek/the-dentist/env/bin/python exists and the case is correct.

(env) Alexeys-MacBook-Pro:bin aamolodc$ ls -li |grep python
   1654565 lrwxr-xr-x  1 aamolodc  staff       9 29 Aug 13:28 python -> python3.6
   1656321 -rwxr-xr-x  1 aamolodc  staff    2359 29 Aug 13:28 python-config
   1654566 lrwxr-xr-x  1 aamolodc  staff       9 29 Aug 13:28 python3 -> python3.6
   1654562 -rwxr-xr-x  1 aamolodc  staff   13068 29 Aug 13:28 python3.6
(env) Alexeys-MacBook-Pro:bin aamolodc$ realpath python
/Users/aamolodc/cloudtrek/the-dentist/env/bin/python3.6

Also, you seem to have duplicated the the-dentist in the following sections of the settings, is that correct.
Yeap, that's the correct folder of our project (a bit confusing :) )

Debugger runs when I change to: "cwd": "/Users/aamolodc/cloudtrek/the-dentist/
I would think that when I specify Python path, it shouldn't then matter what the working directory is, it will find python anyway?
However, I can't change cwd to cater for debugger, as my imports stop working

When I run another script in the same project (with a different working directory), it works perfectly.
Here is config for it:

        {
            "name": "Extractor",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "/Users/aamolodc/cloudtrek/the-dentist/env/bin/python3.6",
            "program": "/Users/aamolodc/cloudtrek/the-dentist/the_dentist/run_extractor.py",
            "cwd": "/Users/aamolodc/cloudtrek/the-dentist",
            "args": [
                "--config" , "the_dentist/config.yml"
            ],
            "env": {
                "PYTHONUNBUFFERED": "1", 
                "PYTHONPATH": "/Users/aamolodc/cloudtrek/the-dentist"
            },
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },

@DonJayamanne
Copy link
Author

Could you try add the following sections into the code and trying to debug:

"console": "integratedTerminal",

The integrated terminal window should open up and and the python executable should be launched from there. Do let me know what is displayed in the terminal window (all of the contents).

@DonJayamanne
Copy link
Author

From @alexmolodchikov on October 6, 2017 3:50

Hey Don, it worked after I ran it in integrated terminal.
Thank you.

It seems like when you just execute a process in the debug mode it uses one set of environment variables, and when you run something in integrated terminal - it flushes all the environment variables and sets everything from launch.json file. I would like to investigate further if you're keen, but saying that the issue is solved.

Cheers.

@DonJayamanne
Copy link
Author

Lets investigate this further if possible. Thanks for the update.

@DonJayamanne
Copy link
Author

@alexmolodchikov are you able to share the source, so I could investigate this further? Thanks

@brettcannon brettcannon added info-needed Issue requires more information from poster area-debugging bug Issue identified by VS Code Team member as probable bug and removed help wanted labels Nov 14, 2017
@brettcannon
Copy link
Member

I'm closing this as it has been over a month since we requested more info. If we do get the info at a later date we can re-open this issue.

@rorycurtis
Copy link

rorycurtis commented Jan 14, 2018

I've hit the same issue, with VS code on Linux

I have to change the cwd because VS Code cannot find local modules e.g.

root
-- moduleA
---- x.py
-- moduleB
---- y.py

If I try to import y.py from x.py then the default settings just don't work because VS Code has no idea how to resolve y.py, when running x.py. So to work around that, I set the cwd to root. At this point, launching x.py from the integrated terminal works fine but the debugger complains that the Python process cannot be found. Both use the same "pythonPath": "${config:python.pythonPath}" setting but the debugger has the different cwd setting.

@brettcannon brettcannon added awaiting 1-verification and removed info-needed Issue requires more information from poster closed-invalid labels Jan 15, 2018
@brettcannon brettcannon reopened this Jan 15, 2018
@brettcannon
Copy link
Member

@rorycurtis can you provide the same info as requested in new issues?

@brettcannon brettcannon added info-needed Issue requires more information from poster and removed awaiting 1-verification labels Jan 15, 2018
@rorycurtis
Copy link

@brettcannon I'm not at liberty to share the source code for the app. Happy to grab any other info you think might be useful.

@brettcannon
Copy link
Member

@rorycurtis that's fine. I'm more looking for log details, raw config details, etc.

@rorycurtis
Copy link

Visual Studio Code:
Version 1.19.2
Commit 490ef761b76b3f3b3832eff7a588aac891e5fe80
Date 2018-01-10T15:57:21.071Z
Shell 1.7.9
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

OS and Python
Xubuntu 16.04
Python 3.6.1 :: Anaconda custom (64-bit)

User settings

{
"python.pythonPath": "~/anaconda/bin/python",
"workbench.colorTheme": "Visual Studio Light"
}

launch.json
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceFolder}/root",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
},

Debug Console Output
Error: spawn /home/xxx/anaconda/bin/python ENOENT

Developer Console Output

[Extension Host] debugger inspector at %cDebugger listening on port 9333.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9333/dc938c25-6fc0-4cb4-8b04-3c17ba1528af

Failed to launch the Python Process, please validate the path '/home/xxx/anaconda/bin/python'
e.doShow @ messageService.ts:126
console.ts:123 [Extension Host] (node:8945) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
t.log @ console.ts:123

console.ts:123 [Extension Host] (node:8945) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
t.log @ console.ts:123

@brettcannon brettcannon added awaiting 1-verification and removed info-needed Issue requires more information from poster labels Jan 16, 2018
@DonJayamanne DonJayamanne self-assigned this Jan 18, 2018
@DonJayamanne
Copy link
Author

@rorycurtis

  • Whats the path to your workspace folder?
  • Do you have a file or folder named .env in your workspace folder?
  • Please could you try debugging using the Integrated Terminal as follows:
    add the entry "console": "integratedTerminal", into your launch configuration as follows:
"configurations": [
    {
        "name": "Python",
        "type": "python",
        "request": "launch",
        "stopOnEntry": false,
        "console": "integratedTerminal",
        "pythonPath": "${config:python.pythonPath}",
        "program": "${file}",
        "cwd": "${workspaceFolder}/root",
        "env": {},
        "envFile": "${workspaceFolder}/.env",
        "debugOptions": [
        "RedirectOutput"
        ]
    },

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed awaiting 1-verification labels Jan 18, 2018
@brettcannon
Copy link
Member

Due to over a month of inactivity after asking for more info, I'm closing this issue. If you are able to provide the requested information in the future we will be happy to open this issue again.

@realdanielbyrne
Copy link

I'm having the same or similar issue. Running from the terminal works, but not with the debugger.

[Running] /usr/bin/python -tt "c:\Dev\google-python-exercises\google-python-exercises\basic\string1.py"
The system cannot find the path specified.
[Done] exited with code=1 in 0.163 seconds

"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}"
    },
    {
        "name": "Python: Attach",
        "type": "python",
        "request": "attach",
        "localRoot": "${workspaceFolder}",
        "remoteRoot": "${workspaceFolder}",
        "port": 3000,
        "secret": "my_secret",
        "host": "localhost"
    },
    {
        "name": "Python: Terminal (integrated)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal"
    },
    {
        "name": "Python: Terminal (external)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "externalTerminal"
    },
    {
        "name": "Python: Django",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/manage.py",
        "args": [
            "runserver",
            "--noreload",
            "--nothreading"
        ],
        "debugOptions": [
            "RedirectOutput",
            "Django"
        ]
    },
    {
        "name": "Python: Flask (0.11.x or later)",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "FLASK_APP": "${workspaceFolder}/app.py"
        },
        "args": [
            "run",
            "--no-debugger",
            "--no-reload"
        ]
    },
    {
        "name": "Python: Module",
        "type": "python",
        "request": "launch",
        "module": "module.name"
    },
    {
        "name": "Python: Pyramid",
        "type": "python",
        "request": "launch",
        "args": [
            "${workspaceFolder}/development.ini"
        ],
        "debugOptions": [
            "RedirectOutput",
            "Pyramid"
        ]
    },
    {
        "name": "Python: Watson",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/console.py",
        "args": [
            "dev",
            "runserver",
            "--noreload=True"
        ]
    },
    {
        "name": "Python: All debug Options",
        "type": "python",
        "request": "launch",
        "pythonPath": "${config:python.pythonPath}",
        "program": "${file}",
        "module": "module.name",
        "env": {
            "VAR1": "1",
            "VAR2": "2"
        },
        "envFile": "${workspaceFolder}/.env",
        "args": [
            "arg1",
            "arg2"
        ],
        "debugOptions": [
            "RedirectOutput"
        ]
    }
]

}

@brettcannon
Copy link
Member

@realdanielbyrne are you using WSL by any chance (based on the interpreter being /usr/bin/python and the file path being Windows-based)? If so, the extension does not support WSL yet (see #67 ).

@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants