Fall back to ascii if the locale module cannot be loaded.
diff --git a/Lib/io.py b/Lib/io.py
index 4ee7cef..b24a21c 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -976,8 +976,13 @@
             except AttributeError:
                 pass
             if encoding is None:
-                import locale
-                encoding = locale.getpreferredencoding()
+                try:
+                    import locale
+                except ImportError:
+                    # Importing locale may fail if Python is being built
+                    encoding = "ascii"
+                else:
+                    encoding = locale.getpreferredencoding()
 
         self.buffer = buffer
         self._encoding = encoding