Skip to content

Setting pythonPath with ${workspaceFolder} in launch.json configs doesn't work #12289

Closed

Description

@koenlek

When I set e.g. this in a config of my workspace's launch.json:

 "pythonPath": "${workspaceFolder}/build/my/own/python",

I get an error about the pythonPath being invalid when I try to run it. As soon as I replace it with the full path it works fine, e.g.

 "pythonPath": "/home/myusername/my_workspace/build/my/own/python",

Note that it works fine with my workspace's settings.json with:

"python.pythonPath": "${workspaceFolder}/build/my/own/python",

I happen to use a custom interpreter and I actually have a variety of workspace folders that draw their settings from a same template for my .vscode settings, so it would be great it we could get the variable to work...

I'm using Ubuntu 18.04, with latest vscode (1.46.0). For anyone trying to debug this: I guess it can be easily reproduced by symlinking your system's python into a folder under your workspaceFolder.

Environment data

  • VS Code version: 1.46.0
  • Extension version (available under the Extensions sidebar): 2020.5.86806
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.17 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): custom
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): N/A?
  • Value of the python.languageServer setting: not set

Expected behaviour

I expect that setting this in my launch.json works:

 "pythonPath": "${workspaceFolder}/build/my/own/python",

Actual behaviour

It doesn't work. But a full path works fine so it seems the variable is not being resolved:

 "pythonPath": "/home/myusername/my_workspace/build/my/own/python",

Steps to reproduce:

Just make a symlink into your workspace to python:

cd to/you/workspace
ln -s $(which python) 

Then create a debug config with:

 "pythonPath": "${workspaceFolder}/python",

Then try to run that debug config

Activity

  1. added
    triage-neededNeeds assignment to the proper sub-team
    bugIssue identified by VS Code Team member as probable bug
    on Jun 11, 2020
  2. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Jun 11, 2020
  3. karrtikr commented on Jun 16, 2020

    @karrtikr

    koenlek This is to notify that we can confirm the bug, thanks. As a workaround, if you want to use the workspace pythonPath setting in launch.json, you can just use,

    "pythonPath": "${command:python.interpreterPath}"
    

    Please let me know if that works for you. If not, please paste the error logs you see on developer tools.

  4. removed their assignment
    on Jun 16, 2020
  5. koenlek commented on Jun 17, 2020

    @koenlek
    Author

    Kartik Raj (@karrtikr), unfortunately, that doesn't work. It gives an error "The Python path in your debug configuration is invalid" once I try to run it. I just feel like any variable expression (e.g. ${...}) under "pythonPath" doesn't work...

  6. karrtikr commented on Jun 17, 2020

    @karrtikr

    That's weird, can you please check the values supported for the property "pythonPath"?
    You can do that in some new launch.json task, adding the property key and then trying to add a value. You should see which options are available

  7. koenlek commented on Jun 17, 2020

    @koenlek
    Author

    Found it! There was a small typo in your suggestion.

    // Correct
    "pythonPath": "${config:python.interpreterPath}"
    // Though your suggestion was:
    "pythonPath": "${command:python.interpreterPath}"
  8. karrtikr commented on Jun 18, 2020

    @karrtikr

    koenlek Can you update to the latest stable version of the extension? We use ${command:python.interpreterPath} in there. Also, does the workaround work?

  9. koenlek commented on Jun 19, 2020

    @koenlek
    Author

    You are right! I assume it changed in a recent release, because I committed the working config to git and after updating my vscode + extensions, the config was changed from "${config:python.interpreterPath}" to "${command:python.interpreterPath}"...

    This workaround works great for me, thanks!

  10. koenlek commented on Jun 19, 2020

    @koenlek
    Author

    Do you want to close the issue? I still think it would be good to make variables like ${workspaceFolder} work better in launch.json for the python plugin...

  11. karrtikr commented on Jun 20, 2020

    @karrtikr

    Yup let's leave it open. It's useful in cases where debugging interpreter is different than the one selected.

  12. karrtikr commented on Oct 22, 2021

    @karrtikr

    Fixed with #17837

  13. locked as resolved and limited conversation to collaborators on Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-debuggingbugIssue identified by VS Code Team member as probable bugverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions