Python 3.13 (currently in beta, due for release in October) will remove lib2to3 from the standard library—the version of yapf specified in requirements.txt (0.25.0, released 2018) depends on this module.
Today I installed Ubuntu 24.04 for WSL from the Windows Store, and its copy of Python 3.12 is missing this module, causing the titular error to be raised:
Traceback (most recent call last):
File "/fake-bpy-module/src/gen.py", line 8, in <module>
import fake_bpy_module as fbm
File "/fake-bpy-module/src/fake_bpy_module/__init__.py", line 3, in <module>
from .generator.generator import generate
File "/fake-bpy-module/src/fake_bpy_module/generator/__init__.py", line 1, in <module>
from . import code_writer
File "/fake-bpy-module/src/fake_bpy_module/generator/code_writer.py", line 4, in <module>
from yapf.yapflib.yapf_api import FormatCode
File "/fake-bpy-module/.venv/lib/python3.12/site-packages/yapf/__init__.py", line 36, in <module>
from yapf.yapflib import file_resources
File "/fake-bpy-module/.venv/lib/python3.12/site-packages/yapf/yapflib/file_resources.py", line 24, in <module>
from lib2to3.pgen2 import tokenize
ModuleNotFoundError: No module named 'lib2to3'
A workaround is to manually install it with apt install python3-lib2to3.
The proper fix for this issue is to require yapf >=0.40.1, which doesn't depend on lib2to3 (ideally the latest version, 0.40.2, which includes other related fixes)—I have been able to generate modules successfully with gen_module.sh using the latest versions of all the packages in requirements.txt, but maybe there are issues I'm not aware of elsewhere in the build/publish pipeline.
One catch is that a Blender commit a few hours ago inserts a \n into a docstring—with 0.25.0 this results in a successful module generation but bpy.ops.extensions.repo_refresh_all() has no description; with 0.40.2 this results in a docutils exception because line 203 of bpy.ops.extensions.rst is unindented. Replacing the \n with a space results in a successful generation (PR).
Thank you for raising the potential issue.
I think updating package version does not affect the generated code for now.
You can submit the patch to update yapf version.
Python 3.13 (currently in beta, due for release in October) will remove
lib2to3
from the standard library—the version ofyapf
specified inrequirements.txt
(0.25.0, released 2018) depends on this module.Today I installed Ubuntu 24.04 for WSL from the Windows Store, and its copy of Python 3.12 is missing this module, causing the titular error to be raised:
A workaround is to manually install it with
apt install python3-lib2to3
.The proper fix for this issue is to require
yapf
>=0.40.1, which doesn't depend onlib2to3
(ideally the latest version, 0.40.2, which includes other related fixes)—I have been able to generate modules successfully withgen_module.sh
using the latest versions of all the packages inrequirements.txt
, but maybe there are issues I'm not aware of elsewhere in the build/publish pipeline.One catch is that a Blender commit a few hours ago inserts a
\n
into a docstring—with 0.25.0 this results in a successful module generation butbpy.ops.extensions.repo_refresh_all()
has no description; with 0.40.2 this results in a docutils exception because line 203 ofbpy.ops.extensions.rst
is unindented. Replacing the\n
with a space results in a successful generation (PR).