首页 > 解决方案 > atom 脚本包和 python 3 的不同输出

问题描述

我在 macOS Mojave 上使用 atom 编辑器和脚本包。

我创建了一个文件,其中包含带有德语变音符号的打印:

 print(hellö)

当我直接在 Atom 中执行文件时,出现以下错误消息:

Traceback (most recent call last):
File "/Users/hambert/runScriptAtom.py", line 1, in <module>
print("hell\xf6")
UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 4: ordinal not in range(128)
[Finished in 0.16s]

在终端

hambert$ python3 /Users/hambert/runScriptAtom.py 
hellö

我检查了版本

import sys
print(sys.version)

完全一样

标签: python-3.xutf-8asciiatom-editor

解决方案


我通过添加解决了它

  PYTHONIOENCODING=utf8

到运行选项中的环境变量


推荐阅读