-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Setting python.sortImports.path
to isort
or setting it to a relative path does not work from within virtual environment
#7042
Comments
Please make sure you've selected the python interpreter (guessing Once a interpreter is selected, setting |
@karrtikr As you can see from my |
I see. As a workaround try using the full path instead. Let me know if that works. Also can you please paste |
Using full path works! This works as well Question is then, is it a bug that just |
If you paste your settings and logs as mentioned in the issue template, i will be able to investigate more. |
Environment data
Actual behaviourWorkspace Settings when it fails: {
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.suggest.localityBonus": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"files.associations": {
".flake8": "ini"
},
"python.autoComplete.addBrackets": true,
"python.jediEnabled": false,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.pythonPath": "${workspaceFolder}/.venv",
"python.sortImports.path": "isort"
} Python plugin output: User belongs to experiment group 'AlwaysDisplayTestExplorer - experiment'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
Starting Microsoft Python language server.
> conda --version
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> ~/project/.venv/bin/python -c "import sys;print(sys.executable)"
> conda info --json
> pipenv --version
cwd: ~/project
> pipenv --venv
cwd: ~/project
> pipenv --py
cwd: ~/project
> ~/project/.venv/bin/python -m flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/project/folder1/pythonfile1.py
cwd: ~/project
> ~/project/.venv/bin/python -m flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/project/folder1/pythonfile1.py
cwd: ~/project
[Info - 10:03:25 AM] Analysis cache path: /home/username/.cache/Microsoft/Python Language Server
[Info - 10:03:25 AM] GetCurrentSearchPaths /home/username/project/.venv/bin/python
[Info - 10:03:25 AM] Interpreter search paths:
[Info - 10:03:25 AM] /home/username/project/.venv/lib/python3.6
[Info - 10:03:25 AM] /home/username/project/.venv/lib/python3.6/lib-dynload
[Info - 10:03:25 AM] /home/username/.pyenv/versions/3.6.9/lib/python3.6
[Info - 10:03:25 AM] /home/username/project/.venv/lib/python3.6/site-packages
[Info - 10:03:25 AM] User search paths:
##########Linting Output - flake8##########
[Info - 10:03:27 AM] Microsoft Python Language Server version 0.3.66.0
[Info - 10:03:27 AM] Initializing for /home/username/project/.venv/bin/python
> conda info --json
> conda --version
> pipenv --version
cwd: ~/project
> pipenv --venv
cwd: ~/project
> pipenv --py
cwd: ~/project
> isort ~/project/folder1/pythonfile1.py --diff
Error: spawn isort ENOENT
> ~/project/.venv/bin/python -m autopep8 --diff ~/project/folder1/pythonfile1.py
cwd: ~/project
> ~/project/.venv/bin/python -m autopep8 --diff ~/project/folder1/pythonfile1.py
cwd: ~/project
> ~/project/.venv/bin/python -m flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/project/folder1/pythonfile1.py
cwd: ~/project
> ~/project/.venv/bin/python -m flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/project/folder1/pythonfile1.py
cwd: ~/project
##########Linting Output - flake8########## |
Thanks for providing the logs. Try running the commands listed in log in the terminal, given your logs I expect running If running it in CLI works, but the extension throws error, then it can be considered an extension issue. Please let me know how it goes. |
@karrtikr Not to steal @thernstig's thunder, I have the same problem and ran The |
@karrtikr Running |
I am able to confirm this is an issue from within virtual environment. |
I also got "spawn isort ENOENT" when I set: "python.sortImports.path": "~/.local/bin/isort" but full path works for me: "python.sortImports.path": "/Users/nathan/.local/bin/isort" |
Not sure about |
@xNathan does using |
@karrtikr |
Very annoying issue. |
@smitthakkar1 that does not work if users have different locations for the virtual env |
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 This results in the extension passing the arguments after a single dash Another issue is that the allowed arguments are wildly different: I compared the help text from For a fix I suggest either updating the version that the extension has built-in or detecting whether the path set in |
Wow... that looks like an ancient issue. Hope someone picks it and fixes. 😞 I'm using it in conjunction with black - and it is ugly to watch how they fight for setting style. I'm using isort 5.10.1 installed using Pipx ob Debian 11 in a Remote Container workflow. Below are possible settings I have in my vscode settings - both work just fine. // individual isort setup using pipx
//"python.sortImports.path": "/usr/local/py-utils/bin/isort",
// isort installed as a dependency during of flake8-isort. injected into flake8 pipx setup.
"python.sortImports.path": "/usr/local/py-utils/venvs/flake8/bin/isort", Was able to fix the setup by including [settings]
profile=black Got excellent compatibility with black formatter. |
Does the vscode team hear about these bug reports? It's a bit odd to just let this things linger for several years. I would think Microsoft has a decent amount of engineering capacity. |
@baregawi well, when you look at contributors stats you will see there's only 9 people with more than 100 commits and half of them were not even active recently. We can try to mention @brettcannon or @karrtikr as it's still really annoying and prevent sharing a proper VSCode config with colleagues. |
Wow, I feel bad. A few warriors are maintaining vscode. I thought there would be much more resources behind it. I really like it. Is there any way I can help with some contributions? |
|
Yes we do. Actually the entire team sees every bug report (we triage as a team in our stand-up).
Not when you have 262 bugs to deal with on top of large amounts of technical debt to clear out. And this is the 8th most requested bug to fix, so it isn't at the top of the list. So I expect we will get to it eventually, but we have other stuff to work through first.
One thing to know is we are in the process of breaking out tool support into their own extensions, and that includes isort. We are putting the tools behind LSP for performance, but it also gives us the chance to rewrite the code from scratch. Based on how we have been structuring things, I suspect that will fix this issue implicitly.
Sure! You can check out https://github.com/microsoft/vscode-python/wiki/Submitting-a-pull-request and the wiki for contributing. Otherwise you can wait for the new extension and give it a try when we announce it. |
I had this issue just now. What worked for me was to create a venv, install the 'isort' module and add this to settings.json:
i.e. pointing directly to the 'isort' module inside the 'venv'. Visual Studio Code - Insiders 1.65.0 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This has been deducted working already as a workaround, see #7042 (comment) The issue is about using the one found in the env if it is in the PATH. Having a relative path is not great in case users share a project VS Code config and users place their venv in different places. |
I am confused about this bug in relation to https://marketplace.visualstudio.com/items?itemName=ms-python.isort According to that extension from Microsoft, it says:
But I have not seen that be the case for this extension where one has to set
|
FYI, I asked a similar question just yesterday at #4922 (comment) regarding the similar Black extension. |
If you're asking why isort is different compared to other supported tools in this extension, it's historical. This extension has shipped isort internally since before it came to Microsoft, so how it handles environment-installed isort has simply always been treated differently.
It's from our team, so we are.
Because we will be removing isort support from this extension once the standalone isort extension is deemed to be working well. The separate extension has much better performance thanks to being behind LSP and thus being able to keep a Python process running, we can update isort in the separate extension more easily (i.e. you can independently roll it back if you don't like an updated version compared to this extension), and we don't have to ship the same bits over and over again like we do in this extension that don't change constantly. |
@brettcannon then I suppose it makes no sense to work on this feature here, if you intend to remove |
Anyone knows how to dynamically link to isort from selected python interpreter? VsCode used to update the "python.pythonPath" variable in settings.json when changing the python interpreter and detect everything properly but does not seem to do it anymore. For now my work around is to use system isort but I hate this solution, I would like to use the one from the selected python interpreter (wihout having to manually change settings.json manually each time). I don't want a relative path solution, really looking for using the selected python interpreter. |
@Greg7000 does #7042 (comment) not work anymore? |
I am not in the #7042 (comment) context. I often switch the selected python interpreter (from VsCode) menu and I can't use relative path since I don't put my virtual env at my project level (using miniconda specific env folder instead).
|
Finally the only way I managed to deal with this issue is to keep |
Close this? The new isort extension https://github.com/microsoft/vscode-isort has the setting |
@thernstig we are actually planning to go through the repo to clean up all the linter and formatter issues once we dropped built-in support, but thanks to the nudge I've gone ahead and close this now. |
Error: Either spawn isort ENOENT" is thrown or isort hangs indefinitely.
Workspace Settings
Using Pipenv, I can do this in the VS Code terminal:
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 #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.
The text was updated successfully, but these errors were encountered: