This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Python 3.6 on Windows problem with source encoding header
Type: compile error Stage: resolved
Components: Interpreter Core Versions: Python 3.6
Status: closed Resolution: duplicate
Dependencies: Superseder: SyntaxError: encoding problem: iso-8859-1 on Windows
View: 20844
Assigned To: Nosy List: eryksun, mniklas
Priority: normal Keywords:

Created on 2018-02-09 13:20 by mniklas, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit mniklas, 2018-02-09 13:20 Compressed source file which shows error, but works well when you delete one of empty lines
Messages (2)
msg311883 - (view) Author: Michal Niklas (mniklas) Date: 2018-02-09 13:20
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
  File "", line 2
SyntaxError: encoding problem: utf8

Works well with Python 2.7:

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

Works well when I delete one empty line:

Python: 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]
ver: $Id: 3367 2018-02-07 07:26:19Z mn $

SHA1 sum of source that breaks Python 3.6:

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

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

[mn:] sha1sum

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

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

[mn:] ll
-rw-rw-r-- 1 mn mn 266 02-09 14:12
msg311893 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-02-09 15:54 uses LF line endings instead of CRLF line endings. This is incompatible with text mode I/O in Microsoft C, which leads to undefined behavior. See issue 20844 and issue 27797.
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76990
2018-02-09 15:54:47eryksunsetstatus: open -> closed

superseder: SyntaxError: encoding problem: iso-8859-1 on Windows

nosy: + eryksun
messages: + msg311893
resolution: duplicate
stage: resolved
2018-02-09 13:20:30mniklascreate