Description
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:
- Basic project structure, where
env1
andenv2
are "pristine" envs created byvirtualenv
.
├── folder1
│ └── env1
├── folder2
│ ├── env2
│ └── test.ipynb
└── workspace.code-workspace
workspace.code-workspace:
{
"folders": [
{
"path": "folder1"
},
{
"path": "folder2"
}
]
}
- Install black in
env2
:source folder2/env2/bin/activate
andpip install black
- Open the workspace in VS Code
- Select interpreter for both folders (the corresponding venv in each folder)
- Open
folder2/test.ipynb
and selectfolder2/env/bin/python
as kernel (will install ipykernel and other stuff) - Try formatting the first cell
- 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