distutils icon indicating copy to clipboard operation
distutils copied to clipboard

AttributeError: module 'distutils' has no attribute 'dep_util'. Did you mean: 'dir_util'? -- however dep_util is included in distribution

Open befeleme opened this issue 1 year ago • 4 comments

Not sure if this behavior is intended or not.

The build of photocollage in Fedora Linux fails with setuptools 69.0.3 with this error:

+ /usr/bin/python3 setup.py build
/usr/lib/python3.12/site-packages/setuptools/_distutils/command/build.py:130: SetuptoolsDeprecationWarning: Direct usage of `distutils` commands
!!

        ********************************************************************************
        It seems that you are using `distutils.command.build` to add
        new subcommands. Using `distutils` directly is considered deprecated,
        please use `setuptools.command.build`.

        This deprecation is overdue, please update your project and remove deprecated
        calls to avoid build errors in the future.

        See https://peps.python.org/pep-0632/ for details.
        ********************************************************************************

!!
  for cmd_name in self.get_sub_commands():
Traceback (most recent call last):
  File "/builddir/build/BUILD/PhotoCollage-1.4.5/setup.py", line 67, in <module>
    distutils.core.setup(
  File "/usr/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 185, in setup
    return run_commands(dist)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
    dist.run_commands()
  File "/usr/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
    super().run_command(command)
  File "/usr/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 131, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
    super().run_command(command)
  File "/usr/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/builddir/build/BUILD/PhotoCollage-1.4.5/setup.py", line 49, in run
    if distutils.dep_util.newer(po, mo):
       ^^^^^^^^^^^^^^^^^^
AttributeError: module 'distutils' has no attribute 'dep_util'. Did you mean: 'dir_util'?

It's my understanding that the module is just deprecated, not made no-op immediately.

When trying things in repl, the behavior observed during the imports is indeed weird:

$ python3.12
>>> from distutils import dep_util
>>> dep_util
<module 'distutils.dep_util' from '/usr/lib/python3.12/site-packages/setuptools/_distutils/dep_util.py'>
$ python3.12
>>> import distutils
>>> distutils.dep_util
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'distutils' has no attribute 'dep_util'. Did you mean: 'dir_util'?

befeleme avatar Jan 18 '24 17:01 befeleme

dep_util is a module and also documented as such (https://docs.python.org/3.11/distutils/apiref.html#module-distutils.dep_util) and PhotoCollage never imports it, so this seems expected.

lazka avatar Jan 19 '24 16:01 lazka

Hello,

I am the author or PhotoCollage and I just discovered this issue while trying to solve a new build problem on Debian that was reported to me: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1077437. I seems the same as the one you encountered @befeleme.

However, on the same system (Fedora Linux 40) and same Python version (3.12.4) I don't experience the problem:

$ python3.12 setup.py build
# works fine
$ python3.12
>>> from setuptools import distutils
>>> from distutils import dep_util
>>> dep_util.newer
<function newer at 0x7f57b30f7060>

For info:

>>> import setuptools
>>> setuptools.__version__
'69.0.3'
>>> import distutils
>>> distutils.__version__
'3.12.4'

@befeleme are you still experiencing the problem (6 months after)?

Does anyone know how imports should be done to have the best compatibility here? https://github.com/adrienverge/PhotoCollage/blob/c74cc3a/setup.py#L20-L25

Thanks!

adrienverge avatar Jul 30 '24 18:07 adrienverge

From what I see the Debian issue was already fixed upstream via https://github.com/adrienverge/PhotoCollage/commit/4496e1905430da64b011ebd94d56514181e98c7c (it added the missing dep_util import)

lazka avatar Jul 30 '24 19:07 lazka

@lazka thank you for the quick answer :zap:

In this case :ok_hand:

adrienverge avatar Jul 30 '24 19:07 adrienverge