Unable to import distutils.dir_util on Windows

橙三吉。 提交于 2019-12-01 03:28:25

On 2.7.5, the oldest I have available, the following works for me:

    #Both imports are needed to avoid errors
    import distutils
    from distutils import dir_util

    distutils.dir_util.copy_tree("./foo", "./bar")

If I leave out "import distutils", I get the error:

NameError: name 'distutils' is not defined

If I leave out the from import, I get the error:

AttributeError: 'module' object has no attribute 'dir_util'

For the last question you ask, I can only guess at why, perhaps the developers may have wanted to hide large parts for the distutils import for size/space/efficiency reasons.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!