Shebang doesn't work with python3

后端 未结 4 1717
执笔经年
执笔经年 2020-12-25 10:54

I have the following program:

#!/usr/local/bin/python3

print(\"Hello\")

Via terminal I do test.py and I get:

         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-25 11:12

    Another reason can be the presence of the byte order mark (BOM) at the start of the file, if the file is using an Unicode encoding.

    The presence of the BOM was my problem for my Python script encoded in UTF-8. I removed the BOM using my text editor Geany, but Notepad++ can also remove it, and I was able to run my script with a starting shebang line with ./myscript.py .

    To quote Wikipedia :

    The Unicode Standard permits the BOM in UTF-8, but does not require or recommend its use. Byte order has no meaning in UTF-8 [...]

提交回复
热议问题