Here is my output of flake8 during validation:
Traceback (most recent call last):
File "/usr/local/bin/flake8", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/flake8/main.py", line 25, in main
flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
File "/usr/local/lib/python2.7/dist-packages/flake8/engine.py", line 244, in get_style_guide
options.exclude.extend(pep8.normalize_paths(EXTRA_EXCLUDE))
AttributeError: 'module' object has no attribute 'normalize_paths'
Why can't I use it?
This problem can be fixed by using an up-to-date version of
flake8, specificallyflake8 >= 2.6.0which does not rely on thepep8module anymore (Source). You can do that by installing it via pip:which should install the newest version (3.5.0 at the moment).
What did go wrong?
This error tells you that flake8 does find a module named
pep8, but that module does not contain a function namednormalize_paths. There can be multiple reasons for that, including a broken installation (which should be fixed be reinstalling flake and pep8) and conflicting versions ofpep8in your path. The latter can happen when you modify yoursys.pathand/ or somehow manage to get an own module named pep8 into your path. This can be as little as a folder named pep8 with an__init__.pyas in this example:As you see this error is a little different that yours but of the same kind. This can be due to minor changes in the
pep8module.To see if everything went well you can check the content of your python path and the location of the
pep8module.This tells you which
pep8module your Python is using. So this should point somewhere into your Python distribution and not into one of your local folders. If it does point into your files this is an issue with yoursys.path, the list of paths that python checks during imports:This shows you all folders that Python searches the
pep8module in (from top to bottom). So if there is a path in there that does point to a location where you would not expect a python package to live, that might be the culprit.(Further Reading: reddit thred)
Other possible solutions
If using the newest version does not sort out your problem you can try using conda to create a virtual environment in which you can install
flake8and all of its dependencies to avoid interactions with other parts of your python installation. After downloading conda, create a new environment (mine is named fl8), activate it, install flake8, and use it:Concerning Emacs
If you launch Emacs from the command line, it uses the same environment as the shell you launched it from. So in order to use flake8 from an environment, like above, you have to activate the environment first. I set up my Emacs with elpy following this tutorial. To make it work with conda I also installed flake etc. into the root environment.
If you launch Emacs a different way (for example using M-F2 on Ubuntu or from the start menu) the environment might not work correctly. I did not fully understand how to fix that yet.