Search code examples
visual-studio-codevscode-extensions

In VSCode how to set the working directory of a new python interactive window?


When executing Jupyter: Create Interactive Window in VScode a new interactive window is opened, how to control the working directory this fresh python interpreter?

Steps in Mac OS:

  1. cmd+shift+P
  2. type Jupyter: Create Interactive Window
  3. a new interactive window is opened
  4. in there type !pwd to see the working directory

How to control in which directory this is? I am working with a multi-root workspace


Solution

  • Changing the order of the paths listed in the work space file (e.g. my_workspace.code-workspace) controls the default working directory when launching a new interactive window.

    The workspace file looks like

    {
      "folders": [
        {
          "path": "."
        },
        {
          "path": "../my_path_1"
        },    {
          "path": "../my_path_2"
        }
      ],
      "settings": {
        "git.enabled": false
      }
    }
    

    The new interactive window will have the working directory of the first path listed above. In this case the the path where my_workspace.code-workspace is located.