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

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

Open
befeleme opened this issue Jan 18, 2024 · 4 comments

Comments

@befeleme
Copy link

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'?
@lazka
Copy link
Contributor

lazka commented Jan 19, 2024

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.

@adrienverge
Copy link

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!

@lazka
Copy link
Contributor

lazka commented Jul 30, 2024

From what I see the Debian issue was already fixed upstream via adrienverge/PhotoCollage@4496e19 (it added the missing dep_util import)

@adrienverge
Copy link

@lazka thank you for the quick answer ⚡

In this case 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants