Search code examples
windows-7-x64python-2.6shutilwindowserror

Shutil cannot import WindowsError on windows


I've observed that shutil fails to import WindowsError on our windows 7 systems:

    from shutil import WindowsError
    File <file>, line <no>, in <module>
        from shutil import WindowsError
    ImportError: cannot import name WindowsError

The same statement works absolutely fine on linux. Has anyone else come across it too? Do you know how I could fix it?

Python version: 2.6.7
Linux OS: Centos 6.3
Windows OS: Windows 7 Professional x64


Solution

  • Got a solution from the python bug tracker:

    http://bugs.python.org/issue18525

    This is an implementation artifact and would not be fixed. The import statement such as above are a wrong usage. The correct usage being(if necessary):

    try:
        WindowsError
    except NameError:
        WindowsError = None