在ubuntu12.04中为python设置UTF8语言环境

2024-06-26 14:45:43 发布

您现在位置:Python中文网/ 问答频道 /正文

在ubuntu12.04vm(使用vagrant和hashicorp/precise64框设置)上,我的语言环境说我有UTF-8语言,但是python得到了latin-1环境。在

我看到的是:

vagrant@vagrant:~$ locale                                                                                                                                 
LANG=en_US.UTF-8                                                                                                                                          
LANGUAGE=                                                                                                                                                 
LC_CTYPE="en_US"                                                                                                                                          
LC_NUMERIC="en_US"                                                                                                                                        
LC_TIME="en_US"                                                                                                                                           
LC_COLLATE="en_US"                                                                                                                                        
LC_MONETARY="en_US"                                                                                                                                       
LC_MESSAGES="en_US"                                                                                                                                       
LC_PAPER="en_US"                                                                                                                                          
LC_NAME="en_US"                                                                                                                                           
LC_ADDRESS="en_US"                                                                                                                                        
LC_TELEPHONE="en_US"                                                                                                                                      
LC_MEASUREMENT="en_US"                                                                                                                                    
LC_IDENTIFICATION="en_US"                                                                                                                                 
LC_ALL=en_US                                                                                                                                              
vagrant@vagrant:~$ python                                                                                                                                 
Python 2.7.3 (default, Feb 27 2014, 19:58:35)                                                                                                             
[GCC 4.6.3] on linux2                                                                                                                                     
Type "help", "copyright", "credits" or "license" for more information.                                                                                    
>>> print u'\u1f41'                                                                                                                                       
Traceback (most recent call last):                                                                                                                        
  File "<stdin>", line 1, in <module>                                                                                                                     
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u1f41' in position 0: ordinal not in range(256)

如何为python获得一个真正的utf-8系统环境?在


Tags: in语言lang环境vmlocaleutfen