diff -r d9a64d00a439 Lib/venv/__init__.py --- a/Lib/venv/__init__.py Fri Jan 13 09:37:56 2017 +0200 +++ b/Lib/venv/__init__.py Fri Jan 13 11:11:22 2017 +0000 @@ -330,19 +330,17 @@ dstfile = os.path.join(dstdir, f) with open(srcfile, 'rb') as f: data = f.read() - if srcfile.endswith('.exe'): - mode = 'wb' - else: - mode = 'w' + if not srcfile.endswith('.exe'): try: data = data.decode('utf-8') data = self.replace_variables(data, context) - except UnicodeDecodeError as e: + data = data.encode('utf-8') + except UnicodeError as e: data = None logger.warning('unable to copy script %r, ' 'may be binary: %s', srcfile, e) if data is not None: - with open(dstfile, mode) as f: + with open(dstfile, 'wb') as f: f.write(data) shutil.copymode(srcfile, dstfile)