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

ModuleNotFoundError: No module named 'distutils' with Python 3.12 #2023

Closed
wrogner opened this issue Oct 9, 2023 · 10 comments
Closed

ModuleNotFoundError: No module named 'distutils' with Python 3.12 #2023

wrogner opened this issue Oct 9, 2023 · 10 comments
Labels
duplicate This issue or pull request already exists

Comments

@wrogner
Copy link

wrogner commented Oct 9, 2023

No module distutils in Python 3.12 makes CustomTkinter traceback:

Traceback (most recent call last):
  File "/Users/wolf/Development/py/9 projects/AVScanner/src/AVScanner/ui/avscanner_ui.py", line 16, in <module>
    from customtkinter import (CTk, CTkFrame, CTkLabel, CTkButton, CTkImage, CTkFont, set_appearance_mode)
  File "/Users/wolf/Development/py/9 projects/AVScanner/venv/lib/python3.12/site-packages/customtkinter/__init__.py", line 10, in <module>
    from .windows.widgets.appearance_mode import AppearanceModeTracker
  File "/Users/wolf/Development/py/9 projects/AVScanner/venv/lib/python3.12/site-packages/customtkinter/windows/__init__.py", line 1, in <module>
    from .ctk_tk import CTk
  File "/Users/wolf/Development/py/9 projects/AVScanner/venv/lib/python3.12/site-packages/customtkinter/windows/ctk_tk.py", line 2, in <module>
    from distutils.version import StrictVersion as Version
ModuleNotFoundError: No module named 'distutils'

See: PEP 632 – Deprecate distutils module

Also (using StrictVersion from distutils):

DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.

(similar to #2022)

@wrogner
Copy link
Author

wrogner commented Oct 9, 2023

Sorry: Reinstalled both 3.11 and 3.12 virtual environments (venv) -> No error messages appear. -> App works.
Nevertheless: the dependency from distutils need be eliminated.

@TechPro424
Copy link

Having the same issue, am not using venvs

@insolor
Copy link

insolor commented Oct 16, 2023

@TechPro424 this is not related to venvs, CustomTkinter simply haven't updated for Python 3.12 yet. For now, you can just downgrade Python to 3.11 version.

In general, it make sense to update to a new Python version (like from 3.11 to 3.12 or 3.12 to 3.13 and so on) not earlier then a half of a year after the release of such version (so that most of major libraries catch up).

@wrogner
Copy link
Author

wrogner commented Oct 16, 2023

If you don't want to accept @insolor 's suggestion of downgrading (for whatever reason):

  • If you don't use a venv, do (that way you isolate the issue to plain Python 3.12 and CustomTkinter).
  • Install fresh with 3.12, customtkinter and setuptools
  • Test a simple window (e.g. https://customtkinter.tomschimansky.com/tutorial/grid-system, which already passes the StrictVersion check).
  • If this works, fine, if not, provide traces.

Regarding "waiting half a year":

  • Adopting new versions is not a question of delay but rather of requirements, thorough testing and careful evaluation.
  • Any platform requires knowledgable early adopters to improve and mature.
  • Waiting without analysis provides no additional benefit.

@insolor
Copy link

insolor commented Oct 16, 2023

After some investigation (ideas of a pull request):

Also, it seems, Version class from packaging can be used: pypa/packaging#520

@wrogner
Copy link
Author

wrogner commented Oct 16, 2023

@insolor : thanks

In CustomTkinter/customtkinter/windows/ctk_tk.py:

replace:

from distutils.version import StrictVersion as Version

with:

from packaging.version import parse as Version

I have to test that a little more, but it seems to work.

@insolor
Copy link

insolor commented Oct 16, 2023

@wrogner

from packaging.version import parse as Version

This is too misleading in my taste (importing a function with a name style of a class).

@wrogner
Copy link
Author

wrogner commented Oct 16, 2023

@insolor
From a programming point of view, I fully agree.
For a quick fix, I think, this would be fastest.

Anyway, it‘s not my code, so whoever fixes it should choose. My part is over here.

@TechPro424
Copy link

I ended up using a venv, and you were right: the issue is that CTK dies not support 3.12.

@TomSchimansky TomSchimansky added the duplicate This issue or pull request already exists label Oct 17, 2023
@TomSchimansky
Copy link
Owner

duplicate of #2005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants