Comply with PEP8 using flake8 and git pre-commit hooks. It will take just a minute.
>>> import python

I found that the method you list doesn’t actually prevent commits. Here’s what I did — and I believe it is closer to the recommended flake8 installation steps (see links at bottom):

python3 -m pip install flake8
python3 -m flake8 --install-hook git
git config --bool flake8.strict true

And to run flake8 manually from the command line:

python3 -m flake8 .

It’s also a good idea to add a .flake8 config file to your git project so you can customize what warnings/errors you want to ignore and what directories to exclude:

ignore = E501
exclude =
max-complexity = 10

Install/help pages for flake8: