Setting `python.sortImports.path` to `isort` or setting it to a relative path does not work from within virtual environment
See original GitHub issueError: Either spawn isort ENOENT" is thrown or isort hangs indefinitely.
Workspace Settings
"python.sortImports.path": "isort",
Using Pipenv, I can do this in the VS Code terminal:
$ which isort
/home/username/project/.venv/bin/isort
If I reload the VS Code window with these settings the Python extension gives an error that says ``spawn isort ENOENT` indicating it cannot find isort.
What am I missing to use a custom isort? In https://github.com/microsoft/vscode-python/issues/6369 I understood there is an inner version, but since users of a project can use different editors it’s better to point out the specific version that we install with pipenv.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:48 (2 by maintainers)
Top Results From Across the Web
VSCode: how to config 'Organize imports' for Python (isort)
The version of isort that is built in to the Microsoft Python plugin doesn't show as isort. Instead it is sortImports.py. It has...
Read more >Configuration options for isort
Values can be file names, directory names or file paths. To skip all files in a nested path use --skip-glob. Type: List of...
Read more >Settings Reference for Python - Visual Studio Code
Settings Reference for the Python extension in Visual Studio Code. ... venvFolders, [], Paths to folders where virtual environments are created.
Read more >coc-pyright - npm
Configuration Description Default
pyright.enable Enable coc‑pyright extension true
python.analysis.autoSearchPaths Automatically add common search paths like 'src' true
python.analysis.typeshedPaths Paths to look for typeshed modules
Read more >isort - Pants build system
The Python import sorter tool (https://pycqa.github.io/isort/). ... a custom lockfile, set this option to a file path relative to the build root, then...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m facing an issue with this workaround as well. It appears that when simply using the full path to the binary, isort runs outside of the virtual env in which it was installed, and as such it cannot identify which installed modules from within the env are 3rd party and sorts them improperly. I now have pylint throwing warnings that 3d party libraries aren’t preceding local packages as they should.
When simply calling isort . from the integrated terminal with the env activated it works as it should tho.
I think I found out what the issue is:
The extension seems to use an old version of isort since that version still is just a
.py
script that is passed to the interpreter. but settingpython.sortImports.path
toisort
loads a newer version which is called directly (isort
instead ofpython isort.py
or whatever the script’s name was).This results in the extension passing the arguments after a single dash
python isort.py - --diff
, while theisort
binary (let’s call it a binary from now on for simplicity) doesn’t need the single dash and gets confused by it (it just hangs indefintiely expecting a stream).Another issue is that the allowed arguments are wildly different: I compared the help text from
isort
5.9.3 and whatever version the extension has built in and the allowed argument list is different, and the arguments for the same things differ between the 2 versions. (for instance a lot of the verbose arguments (--max-line-length
instead of-l
) are not available in the builtin version.For a fix I suggest either updating the version that the extension has built-in or detecting whether the path set in
python.sortImports.path
is a python file or a “binary” and remove the single dash accordingly.