summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py9
1 files changed, 7 insertions, 2 deletions
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 @@ class TextIOWrapper(TextIOBase):
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