[New-bugs-announce] [issue32809] Python 3.6 on Windows problem with source encoding header

Michal Niklas report at bugs.python.org
Fri Feb 9 08:20:30 EST 2018


New submission from Michal Niklas <mniklas at users.sourceforge.net>:

I have strange error with source encoding header. I usually use it from template which looks like:

#!/usr/bin/env python
# -*- coding: utf8 -*-

This works well on Linux machines with Python 2.x and 3.x, but on Windows machines it works well only with Python 2.x. When I use Python 3.6 it often works, but for some sources interpreter reports:

SyntaxError: encoding problem: utf8

It is easy to "correct": you can change "utf8" to "utf-8".

Strange thing is that even on Windows with Python 3.6 it works well with the same source encoding header but with little edited source file. I tried to create simplest file that shows this error but works well when I delete one empty line.

Error on Windows with Python 3.6:

c:\temp>C:\Users\mn\AppData\Local\Programs\Python\Python36-32\python.exe zz2_err
.py
  File "zz2_err.py", line 2
SyntaxError: encoding problem: utf8


Works well with Python 2.7:

c:\temp>zz2_err.py
Python: 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]
ver: $Id: zz.py 3367 2018-02-07 07:26:19Z mn $


Works well when I delete one empty line:

c:\temp>C:\Users\mn\AppData\Local\Programs\Python\Python36-32\python.exe zz2_err.py
Python: 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]
ver: $Id: zz.py 3367 2018-02-07 07:26:19Z mn $

SHA1 sum of source that breaks Python 3.6:

c:\temp>fciv -sha1 zz2_err.py
//
// File Checksum Integrity Verifier version 2.05.
//
4176921690c9ea9259c57c9fcc3cda84aa51015e zz2_err.py

The same source on Linux works well with both Python 2.7 and Python 3.6:

[mn:] sha1sum zz2_err.py
4176921690c9ea9259c57c9fcc3cda84aa51015e  zz2_err.py

[mn:] python zz2_err.py
Python: 2.7.13 (default, Dec  1 2017, 09:21:53)
[GCC 6.4.1 20170727 (Red Hat 6.4.1-1)]
ver: $Id: zz.py 3367 2018-02-07 07:26:19Z mn $

[mn:] python3 zz2_err.py
Python: 3.5.4 (default, Oct  9 2017, 12:07:29)
[GCC 6.4.1 20170727 (Red Hat 6.4.1-1)]
ver: $Id: zz.py 3367 2018-02-07 07:26:19Z mn $

[mn:] ll zz2_err.py
-rw-rw-r-- 1 mn mn 266 02-09 14:12 zz2_err.py

----------
components: Interpreter Core
files: zz2_err.zip
messages: 311883
nosy: mniklas
priority: normal
severity: normal
status: open
title: Python 3.6 on Windows problem with source encoding header
type: compile error
versions: Python 3.6
Added file: https://bugs.python.org/file47432/zz2_err.zip

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32809>
_______________________________________


More information about the New-bugs-announce mailing list