Shebang executable not found because of UTF-8 BOM (Byte Order Mark)

前端 未结 2 1359
感情败类
感情败类 2020-12-11 08:43

For some reason the shebang in one of my scripts does not work:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
print \"Hello World\"

When I

2条回答
  •  一整个雨季
    2020-12-11 09:13

    This is due to how Unix and Linux handle the shebang. #! must be the first two bytes in the file. If you have a BOM then this isn't true anymore hence the error.

    Note that putting a BOM is completely useless from the point of view of the python interpreter, since the # -*- coding: utf-8 -*- already tells python the encoding.

    AFAIK BOM is usually not used with utf-8. It is used for UTF-16 et similia in order to specify the byte-order. If the editor assumes the wrong encoding you should be able to explicitly open the file with the correct encoding.

提交回复
热议问题