Python 3.11 ModuleNotFoundError: No module named 'tomllib'

See original GitHub issue

Describe the bug

In Python 3.11 it is raising exception with ModuleNotFoundError.

To Reproduce

Install Python 3.11

$ black .

The resulting error is:

Traceback (most recent call last):
  File "/home/runner/work/autodonate/autodonate/.venv/bin/black", line 5, in <module>
    from black import patched_main
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/autodonate/autodonate/.venv/lib/python3.11/site-packages/black/__init__.py", line 52, in <module>
    from black.files import (
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/autodonate/autodonate/.venv/lib/python3.11/site-packages/black/files.py", line 25, in <module>
    import tomllib
    ^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'tomllib'

Environment

  • Black’s version: 22.3.0
  • OS and Python version: Github Actions Ubuntu, Python 3.11

Additional context

Logs from my CI. Also, why you haven’t did any CI on 3.11?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
pawamoycommented, Apr 1, 2022

Would it be possible to change to a try/except (and put back tomli as dep without marker) instead of a condition on the Python version, at least until tomllib is available in Python 3.11 (alpha or not)? I understand 3.11 is still alpha, but I believe many users want to test their code and run their CI tools (i.e. Black) on Python 3.11. Of course I can pin Black to <22.3 for Python 3.11 only (with markers), but that’s a bit cumbersome to do in every project 😕

1reaction
JelleZijlstracommented, Apr 1, 2022

@pawamoy that’s fair, opened #2987

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 3.11 Preview: TOML and tomllib
Python 3.11 comes with a new module in the standard library named tomllib . You can use tomllib to read and parse any...
Read more >
Update Python `3.11-dev` - Travis CI Community
Python 3.11-dev on the focal image is still using 3.11.0a3+. Python 3.11 is ... ModuleNotFoundError: No module named 'tomllib' · Issue #1390 ......
Read more >
tomllib — Parse TOML files — Python 3.11.1 documentation
Source code: Lib/tomllib This module provides an interface for parsing TOML (Tom's Obvious Minimal Language, https://toml.io). This module does not support ...
Read more >
Python 3.11 is Coming! Here's How It Fares Against Python 3.10
According to the Python Software Foundation (PSF), Python 3.11 is in it's 7th alpha revision and is ... ModuleNotFoundError: No module named 'tomllib'....
Read more >
Top 3 Radical New Features in Python 3.11 - Prepare Yourself
That changes now. Below is the code snippet we'll run in both containers: import tomllib DOC = """ [main] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found