Disable python import sorting in VSCode

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]

Leave a Comment