[VScode] autopep8 format does not work [Python]

Overview

It worked on my office PC, but my autopep8 formatter didn't work in my home VScode and I was discouraged. -> The problem is in the settings

environment

Besides autopep8, I used flake8 and mypy. The environment is venv using Pipenv (It is not related to this problem because there is no problem if the interpreter is properly selected on VScode.)

Settings and symptoms

Settings.json looks like this. Although formatOnSave works, it is not formatted, and there is no response when I format the document by right-clicking. However, the format (`` `$ autopep8 sample.py```) from the command line worked.

settings.json


  "editor.formatOnSave": true,
 "python.linting.enabled": true,
  "python.linting.pylintEnabled": false,
  "python.linting.flake8Enabled": true,
  "python.linting.flake8Args": [
    "--ignore=E402, E501, W503"
  ],
  "python.formatting.autopep8Args": [
    "--ignore=E50", //Start a new line with a semicolon
    "--max-line-length=120",
    "--aggressive",
    "--aggressive",
  ],
  "python.jediEnabled": false,
  "python.linting.mypyEnabled": true,

Solution

It was too hard to write without the formatter working, so I desperately searched.

There was such an issue. autopep8 formatting not working #2843 https://github.com/Microsoft/vscode-python/issues/2843

@thernstig your settings aren't quite right; you want as you have to make each individual item you would pass on the command line an individual thing in the array:

"python.formatting.autopep8Args": ["--max-line-length", "100"]

You need to pass the individual items in the array to the command line. (Free translation)

The following part was wrong.

settings.json


  "python.formatting.autopep8Args": [
    "--ignore", 
    "E50",
    "--max-line-length",
    "120",
    "--aggressive",
    "--aggressive",
  ],

You can set autopep8 as follows, but in settings.json it seems that you need to pass it individually in the array. It was written in the same way as the item setting of flake8 above due to brain death ...

usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename]
                [--ignore-local-config] [-r] [-j n] [-p n] [-a]
                [--experimental] [--exclude globs] [--list-fixes]
                [--ignore errors] [--select errors] [--max-line-length n]
                [--line-range line line] [--hang-closing] [--exit-code]
                [files [files ...]]

Recommended Posts

[VScode] autopep8 format does not work [Python]
Virtualenv does not work on Python3.5 (Windows)
Jinja2 2.9.6 does not work on Lambda Python 3 series
Python version does not switch
LocateCenterOnScreen does not work on PyAutoGui
gqlgen command does not work with go gqlgen
Python> Python does not include the last offset
Check items when the imported python module does not work as expected
Opencv4.1 + Windows10 + Python 3.7.5 cv2.VideoCapture does not display correctly
Python string format
After installing php7.2, the php command does not work
Python string format
format in python
[Python] Expression (1,2) does not make tuples with parentheses
When wildcard specification does not work with pylint
Patch when full text search does not work in GAE / Python local environment
python Boolean operation does not return a Boolean value
What to do when python3 type venv does not work well on Raspberry Pi
[Python] Precautions when it does not work even if TimedRotatingFileHandler is set in basicConfig in python2
Note ((1) csv.reader AttributeError, (2) get_sheet_by_name DeprecationWarning, (3) .delete_cols does not work)
[Python] Boolean operator (or / and) does not return Boolean value
Command when ACPI shutdown does not work in VirtualBox
The story that yapf did not work in vscode
Parallel processing of Python joblib does not work in uWSGI environment. How to process in parallel on uWSGI?
python variable expansion, format
Python Not Implemented Error
I tried Python> autopep8
vscode doesn't recognize python
Image format in Python
Python Pickle format notes
[Python] format methodical use
How tuples work | Python
VScode intellisense doesn't work on Raspberry Pi OS 64bit! (Python)
[Python] Reason why index error does not occur in slice
The story that `while queue` did not work in python
Day 65 (Solution) Jupyter notebook does not work with Kernel Not Conected.
Python error support note: "... does not support argument 0 of type float ..."
[VSCode] unable to import'google.cloud' What to do when pylint (import-error) does not recognize the Python import statement
After creating and applying a virtual environment of python3.8.0, code completion did not work with vscode