Skip to content

Wrong interpreter is chosen when running Format Cell in Jupyter Notebook in a mulltiroot workspace #18499

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

Closed
somiandras opened this issue Feb 10, 2022 · 3 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue

Comments

@somiandras
Copy link

somiandras commented Feb 10, 2022

Issue Type: Bug

Behaviour

Expected vs. Actual

This is likely related to #18482, but not an exact duplicate.

Expected

When in a Jupyter Notebook, selecting Format Cell (either in context menu or via keyboard shortcut) the selected formatter (black in my case) runs from the Python interpreter path I selected for the kernel (which is the same in my case as the Python interpreter selected for the workspace folder).

Actual:

Even though the Python code in the notebook uses the kernel correctly, the formatter tries to run with the interpreter from another workspace folder (probably selected in alphabetical order from the workspace folders).

Steps to reproduce:

  1. Basic project structure, where env1 and env2 are "pristine" envs created by virtualenv
.
├── folder1
│   └── env1
├── folder2
│   ├── env2
│   └── test.ipynb
└── workspace.code-workspace

workspace.code-workspace:

{
  "folders": [
    {
      "path": "folder1"
    },
    {
      "path": "folder2"
    }
  ]
}
  1. Install black in env2: source folder2/env2/bin/activate and pip install black
  2. Open the workspace in VS Code
  3. Select interpreter for both folders (the corresponding venv in each folder)
  4. Open folder2/test.ipynb and select folder2/env/bin/python as kernel (will install ipykernel and other stuff)
  5. Try formatting the first cell
  6. Python output:
> ~/Code/data-projects/code_bug/folder1/env1/bin/python -m black --diff --quiet ~/Code/data-projects/code_bug/folder2/test.ipynb.9ebb3da53d64cf750c7de10b06c69f78.tmp
cwd: ~/Code/data-projects/code_bug/folder1
> ~/Code/data-projects/code_bug/folder1/env1/bin/python -c "import black"
> ~/Code/data-projects/code_bug/folder1/env1/bin/python -c "import black"

Formatting with black failed.
You could either install the 'black' formatter, turn it off or use another formatter.
Error: Module 'black' not installed.

Notice that black was run as code_bug/folder1/env1/bin/python -c "import black".

I'd expect it to run from folder2/env2/bin/python as that's the kernel and the workspace folder interpreter too (I'm not sure which one should be the relevant here...)

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.9
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
User Settings


defaultLS: {"defaultLSType":"Pylance"}

downloadLanguageServer: true

envFile: "<placeholder>"

venvPath: "<placeholder>"

venvFolders: "<placeholder>"

condaPath: "<placeholder>"

pipenvPath: "<placeholder>"

poetryPath: "<placeholder>"

languageServer: "Pylance"

linting
• enabled: true
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: false
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: false
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: true
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"

sortImports
• args: "<placeholder>"
• path: "<placeholder>"

formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "black"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"

testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: undefined
• nosetestPath: "<placeholder>"
• promptToConfigure: false
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: true

terminal
• activateEnvironment: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"

experiments
• enabled: false
• optInto: []
• optOutFrom: []

insidersChannel: "off"

tensorBoard
• logDirectory: "<placeholder>"

Extension version: 2022.0.1814523869
VS Code version: Code 1.64.1 (d6ee99e4c045a6716e5c653d7da8e9ae6f5a8b03, 2022-02-07T17:26:08.977Z)
OS version: Darwin x64 18.7.0
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz (4 x 2500)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 7, 7, 5
Memory (System) 16.00GB (0.05GB free)
Process Argv --crash-reporter-id b90c2562-f8c4-4123-a66e-f81cefecbc1c
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30425749
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
pythondataviewer:30285071
vscod805cf:30301675
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
vsc1dsc:30433058
pythonvs932:30410667
wslgetstarted:30433507
vscop940:30404999
vsrem710:30416614

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 10, 2022
@karthiknadig karthiknadig added area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug triage and removed triage-needed Needs assignment to the proper sub-team labels Feb 10, 2022
@karrtikr karrtikr added investigating We are looking into the cause of the issue and removed triage labels Feb 10, 2022
@karrtikr
Copy link

Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can.

@karrtikr
Copy link

karrtikr commented Apr 19, 2022

Python interpreter path selected for the kernel and interpreter path selected by the Python extension are different, AFAIU formatters are taken care of in the Python extension so this is expected.

Please provide the full Python log capturing the whole process, which lets us know of interpreters you've selected in each folder.

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Next steps would be to transfer this over to the Jupyter team to see if there's anything to be done here.

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Apr 19, 2022
@brettcannon
Copy link
Member

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

4 participants