找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 4143|回复: 2

[求助] python 中文乱码,请大神解惑

6

主题

8

帖子

8

积分

贫民

积分
8
tingyanqinxing 发表于 2017-3-18 19:19:44 | 显示全部楼层 |阅读模式
操作系统:
[root@skyofus cgi-bin]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)



python版本及输出中文乱码实例:
Python 3.5.3 (default, Mar  5 2017, 14:22:21)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('舒服舒服')
  File "<stdin>", line 0
    ^
SyntaxError: 'ascii' codec can't decode byte 0xe8 in position 7: ordinal not in range(128)
>>> import sys
>>> sys.stdout.encoding
'ANSI_X3.4-1968'

---------------------------------------------------------------分割线-----------------------------------
Python 2.7.5 (default, Sep 15 2016, 22:37:39)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print('水电费')
  File "<stdin>", line 1
    print(ਦ°´电费')
          ^
SyntaxError: invalid syntax
>>> print('水电费   ')
水电费
>>> sys.stdout.encoding
'ANSI_X3.4-1968'


回复

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2017-3-18 21:52:11 | 显示全部楼层
python3.4.4, win10
回复 支持 反对

使用道具 举报

6

主题

8

帖子

8

积分

贫民

积分
8
tingyanqinxing  楼主| 发表于 2017-3-19 12:59:20 | 显示全部楼层
解决了,我的操作系统语言为英文,更改系统语言为中文就ok了。我的操作系统为centos7.2
vim /etc/locale.conf
LANG='zh_CN.UTF-8'
重启系统之后OK
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表