Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MatthijsBurgh opened this issue Apr 8, 2024 · 3 comments

Comments

@MatthijsBurgh
Copy link

MatthijsBurgh commented Apr 8, 2024

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 PyCQA/pycodestyle@f04e2a1 (See also PyCQA/pycodestyle#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
Copy link
Author

This seems to be fixed in 6.1 and 7.0, 9786562. Is this going to be released on Ubuntu 24.04?

@MatthijsBurgh
Copy link
Author

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

@asottile
Copy link
Member

asottile commented Apr 8, 2024

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

@PyCQA PyCQA locked as off-topic and limited conversation to collaborators Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants