PyCQA / flake8

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.
https://flake8.pycqa.org
Other
3.39k stars 306 forks source link

Flake8 failed to load plugin "pycodestyle" due to cannot import name 'missing_whitespace_around_operator' from 'pycodestyle' #1928

Closed MatthijsBurgh closed 5 months ago

MatthijsBurgh commented 5 months ago

how did you install flake8?

# Ubuntu 24.04
sudo apt-get install python3-flake8

python3-flake8: 5.0.4-4
python3-mccabe: 0.7.0-1
python3-pycodestyle: 2.11.1-1
python3-pyflakes: 3.2.0-1

unmodified output of flake8 --bug-report

python3 -m flake8 --bug-report
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flake8/plugins/finder.py", line 296, in _load_plugin
    obj = plugin.entry_point.load()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/lib/python3/dist-packages/flake8/plugins/pycodestyle.py", line 25, in <module>
    from pycodestyle import missing_whitespace_around_operator as _missing_whitespace_around_operator  # noqa: E501
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name 'missing_whitespace_around_operator' from 'pycodestyle' (/usr/lib/python3/dist-packages/pycodestyle.py). Did you mean: 'whitespace_around_operator'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3/dist-packages/flake8/__main__.py", line 5, in <module>
    raise SystemExit(main())
                     ^^^^^^
  File "/usr/lib/python3/dist-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/usr/lib/python3/dist-packages/flake8/main/application.py", line 336, in run
    self._run(argv)
  File "/usr/lib/python3/dist-packages/flake8/main/application.py", line 324, in _run
    self.initialize(argv)
  File "/usr/lib/python3/dist-packages/flake8/main/application.py", line 302, in initialize
    self.find_plugins(
  File "/usr/lib/python3/dist-packages/flake8/main/application.py", line 128, in find_plugins
    self.plugins = finder.load_plugins(raw, opts)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/flake8/plugins/finder.py", line 370, in load_plugins
    return _classify_plugins(_import_plugins(plugins, opts), opts)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/flake8/plugins/finder.py", line 312, in _import_plugins
    return [_load_plugin(p) for p in plugins]
            ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/flake8/plugins/finder.py", line 298, in _load_plugin
    raise FailedToLoadPlugin(plugin.package, e)
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "pycodestyle" due to cannot import name 'missing_whitespace_around_operator' from 'pycodestyle' (/usr/lib/python3/dist-packages/pycodestyle.py).

describe the problem

Flake8 fails to import missing_whitespace_around_operator from pycodestyle. This function has been merged with missing_whitespace in https://github.com/PyCQA/pycodestyle/commit/f04e2a1f5d37f8668519f123b97bf38165994b72 (See also https://github.com/PyCQA/pycodestyle/issues/1191)

This only happens on Ubuntu 24.04, not on Ubuntu 22.04. As on 22.04 pycodestyle is still on 2.8.0-2.

what I expected to happen

To generate a bug report.

sample code

Any flake8 call

commands ran

$ flake8 --bug-report
MatthijsBurgh commented 5 months ago

This seems to be fixed in 6.1 and 7.0, https://github.com/PyCQA/flake8/commit/9786562feb573d30c73f18e1a0a6685c8584e9b5. Is this going to be released on Ubuntu 24.04?

MatthijsBurgh commented 5 months ago

Closing this as a fix has been made, see https://bugs.launchpad.net/ubuntu/+source/python-flake8/+bug/2012523

asottile commented 5 months ago

please next time read the issue template and the things it links to. it explicitly calls out this case where operating system packagers do dumb things and force incompatible versions. it also invites you to search and find the several duplicates with your exact error message