Search code examples
pythonpython-3.xdistutilsdeprecation-warning

Python 3.10 deprecation warning for distutils


DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.dir_util import copy_tree

Is it something that I should worry about? Which import should I use to replace the from distutils.dir_util import copy_tree line?


Solution

  • Change from:

    from distutils.dir_util import copy_tree
    copy_tree(loc_source, loc_destination)
    

    To:

    import shutil
    shutil.copytree(loc_source, loc_destination)
    

    Or, to replace existing files and folders:

    import shutil
    shutil.copytree(loc_source, loc_destination, dirs_exist_ok=True)
    

    Documentation: https://docs.python.org/3/library/shutil.html#shutil.copytree