解决pycharm 中 python3 的环境编码是 ASCII 转化为utf-8Click will abort further execution because Python 3

自己的一个小项目中因为 使用 了 6.7 的 click 包,结果就发现 一直编码不对,其实也是有问题,之前没啥事情,很突然就不能运行了, 甚至感觉好像是换了ip 后发生的。
还有一个有趣的现象就是 不管怎么设置就是不见效,还有就是 在 Terminal 都已经是 utf-8了,但是在pycharm 还是 ASCII。好奇怪

最后不过还是解决了
参考
https://stackoverflow.com/questions/36651680/click-will-abort-further-execution-because-python-3-was-configured-to-use-ascii?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

https://github.com/madjar/nox/issues/19

Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment

If you are trying to execute tests case you must set the following environment variables each time:

export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
Doing this each time will resolve the error.
It may also be possible to set this in your IDE if you are using one. For example see the following setting in PyCharm 2016.

image.png

修改 运行配置 ,我 甚至把default 里的python 的 Envrionment Variable 参数也都添加了, pycharm 的右上角的运行 配置 configuration edit 就可以

另外 在程序中 也是可以配置和 查看 编码

import locale
print(locale.getpreferredencoding())
print(codecs.lookup(locale.getpreferredencoding()).name)

locale.setlocale(locale.LC_ALL,"en_US.UTF-8")
print(locale.getpreferredencoding())

另外 也可以配置
export PYTHONIOENCODING=UTF-8

另外 click 包Doc 也提到了这些编码问题

http://click.pocoo.org/5/

http://click.pocoo.org/5/python3/#python-2-and-3-differences

你可能感兴趣的:(解决pycharm 中 python3 的环境编码是 ASCII 转化为utf-8Click will abort further execution because Python 3)