I am trying to disable vscode from formatting my python imports when I save my file. I have some code that must run in between various imports so order is important, but every time I save it just shoves the imports to the top.
I tried putting
"editor.codeActionsOnSave": { "source.organizeImports": false },
in my user settings but that doesn't fix it.
Thanks!
EDIT- I would like to keep formatting on save on except for the imports
To disable auto imports, set "javascript. suggest. autoImports" to false .
Set the correct Python path in VSCode In order to fix Unresolved Import in VSCode, you have to set python. pythonPath key in the settings to the correct value. You can quickly open the settings. json editor by accessing File > Preferences or press Ctrl + , key combination.
Check for the below setting in vscode settings, if it's true then set it to false for completely disabling formatting on save, like so :
"editor.formatOnSave": false
for formatting and to ignore imports not being at top itself, first make the above setting true and add to your user settings and try adding this setting to your user settings, if you're using the default formatter for python, that is autopep8 :
"python.formatting.autopep8Args": ["--ignore","E402"]
where E402 represents "module level import not at top of file"
Note that this would only work if you are using the default formatter/linter. If you are using some other linter then i suggest you look up their documentation to see how it's done. Like most commonly one could make use of global config file, say $HOME/.config/.pycodestyle, and add necessary settings there, like :
[pycodestyle] ignore = E402
EDIT : the arguments for the formatter should be passed as separate list items in quotes like ["--ignore","E402"] rather than [--ignore=E402]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With