python.languageServer setting: JediGiven input file main.py:
from typing import List, Optional
from datetime import datetime
print("Hello World")
Using the python extension's "Python Refactor: Sort Imports" command, it should rearrange the imports in alphabetical order to the following:
from datetime import datetime
from typing import List, Optional
print("Hello World")
After pressing cmd+shift+P and selecting "Python Refactor: Sort Imports", I get this little error popup saying "write EPIPE" (see image).

NOTE: this works properly when runningisort main.py manually from the terminal
./.vscode/settings.json
{
"python.pythonPath": "venv/bin/python",
"python.sortImports.path": "isort"
}
virtualenv venvsource venv/bin/activatepip install isortcmd+shift+P on mac)N/A
Figured it out, silly mistake.
Change the value of python.sortImports.path to "venv/bin/isort" and it works now (although a more helpful error message could be a QOL improvement).
./.vscode/settings.json
{
"python.pythonPath": "venv/bin/python",
"python.sortImports.path": "venv/bin/isort"
}
@hkennyv it's not a mistake - this is an error, "python.sortImports.path": "isort" should work the same way the isort command works within virtualenv (and for other tools like e.g. black that's working with no problem).
@jaklan that is exactly what I thought the case would be, seeing how black is handled in the settings.json. I can confirm this is still an issue on my current vscode version:
Version: 1.49.0-insider
Commit: bd08768fd310d34cdd4423a53e5f3ca77340fea5
Date: 2020-08-14T06:47:57.598Z (17 hrs ago)
Electron: 9.2.0
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 18.7.0
I'll reopen this since I'm not the only one expecting this behavior, thanks!
nevermind.. can't seem to reproduce this issue haha
nevermind.. can't seem to reproduce this issue haha
What do you mean? You used "python.sortImports.path": "isort" and it worked?
@jaklan I believe it was due to an issue with an outdated version of isort (see #12932). I've updated all my dependencies and wasn't able to reproduce it. I even spent a lot of time putting together a PR, only to find out it may have been an older version of isort
@jaklan I believe it was due to an issue with an outdated version of isort (see #12932). I've updated all my dependencies and wasn't able to reproduce it. I even spent a lot of time putting together a PR, only to find out it may have been an older version of isort
But these issues are completely unrelated. The linked one is about updating a version of isort shipped with VS Code (used when "python.sortImports.path" is empty) and the problem with "python.sortImports.path": "isort" occurs when you want to use isort installed within your e.g. virtual env. The second use-case is an unresolved problem for a quite long time, so if you make it work with your PR - please, open it again!
@jaklan It seems to work for me now using both venv/bin/isort and just isort, so i closed it since i'm not able to reproduce it at the moment 🤷♂️.. if you're still facing this issue, i'll gladly reopen though!
@hkennyv yeah, still facing, but I've just compared our versions:
Version: 1.48.0
Commit: db40434f562994116e5b21c24015a2e40b2504e6
Date: 2020-08-13T08:03:27.059Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.7.0
I'll install the insider one and share the result in a moment.
If you don't mind, could you share your settings.json and output of python -m pip list? @jaklan
@hkennyv I've just tried VSCode Insiders:
Version: 1.49.0-insider
Commit: bd08768fd310d34cdd4423a53e5f3ca77340fea5
Date: 2020-08-14T06:47:57.598Z
Electron: 9.2.0
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 18.7.0
with such a config:
{
"python.pythonPath": ".venv/bin/python",
"python.formatting.provider": "black",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"editor.formatOnSave": true,
"python.sortImports.path": "isort"
}
and I don't get write EPIPE error, but the effect is the same - isort simply doesn't work, but black - yes. Virtual env is activated of course and when running isort from CLI - everything is okay. But what's more interesting - even if I switch to the built-in isort (so leave the path empty), it also doesn't work anymore.
@jaklan and what about your version of isort? i was fairly certain the issue came down to that, but I could definitely be wrong. Thanks for posting, I'll reopen this!
@hkennyv the latest one (5.4.2, previously 5.4.1). I have tried one more thing in Insiders - run Python Refactor: Sort Imports command by hand and:
write EPIPE error when using "python.sortImports.path": "isort" (details below)"python.sortImports.path": ""So exactly the same behaviour as previously. The only difference is the Format Document command which is now broken and it doesn't sort imports regardless of which isort, built-in or virtualenv-based, I use (also in Format on save mode).
mainThreadExtensionService.ts:65 [[object Object]]write EPIPE
$onExtensionRuntimeError @ host.ts:10
mainThreadExtensionService.ts:66 Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:149)
at writeGeneric (internal/stream_base_commons.js:140)
at Socket._writeGeneric (net.js:776)
at Socket._write (net.js:788)
at doWrite (_stream_writable.js:435)
at writeOrBuffer (_stream_writable.js:419)
at Socket.Writable.write (_stream_writable.js:309)
at b.communicateWithIsortProcess (/Users/jaklan/.vscode-insiders/extensions/ms-python.python-2020.9.101620-dev/out/client/extension.js:48)
at t.pythonExecutionFactory.create.resource (/Users/jaklan/.vscode-insiders/extensions/ms-python.python-2020.9.101620-dev/out/client/extension.js:48)
at b._provideDocumentSortImportsEdits (/Users/jaklan/.vscode-insiders/extensions/ms-python.python-2020.9.101620-dev/out/client/extension.js:48)
at processTicksAndRejections (internal/process/task_queues.js:94)
Two more related issues:
I just want to quickly acknowledge that we have received the issue and will be looking into it soon.
@jaklan @hkennyv This is a duplicate of https://github.com/microsoft/vscode-python/issues/7042. The error message is different from one before because we changed how we're running isort, but it's the same issue.