python3 ascii转utf8_解决pycharm 中 python3 的环境编码是 ASCII 转化为utf-8Click will abort further execution becau...

自己的一个小项目中因为 使用 了 6.7 的 click 包,结果就发现 一直编码不对,其实也是有问题,之前没啥事情,很突然就不能运行了, 甚至感觉好像是换了ip 后发生的。

还有一个有趣的现象就是 不管怎么设置就是不见效,还有就是 在 Terminal 都已经是 utf-8了,但是在pycharm 还是 ASCII。好奇怪

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 也提到了这些编码问题

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值