env LC_ALL = C和python UnicodeEncodeError

时间:2018-04-25 14:46:00

标签: python linux unicode

linux env LC_ALL = C执行chagne语言环境,但是它导致python UnicodeEncodeError如下所示。 stackexchange的What does “LC_ALL=C” do?确实很有帮助。 python的编解码器与LC_ALL有什么关系?任何人都可以帮助解释LC_ALL = C和unicode之间的关系吗?

$ unset LC_ALL  
$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
$ export LC_ALL=C
$ locale
LANG=en_US.utf8
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C
$ deeptools
['/share/apps/anaconda3/bin', '/share/apps/anaconda3/lib/python2.7', '/share/apps/anaconda3/lib/python36.zip', '/share/apps/anaconda3/lib/python3.6', '/share/apps/anaconda3/lib/python3.6/lib-dynload', '/share/apps/anaconda3/lib/python3.6/site-packages', '/share/apps/anaconda3/lib/python3.6/site-packages/Sphinx-1.5.6-py3.6.egg', '/share/apps/anaconda3/lib/python3.6/site-packages/CIRCexplorer2-2.3.2-py3.6.egg', '/share/apps/anaconda3/lib/python3.6/site-packages/phylotoast-1.3.0-py3.6.egg', '/share/apps/anaconda3/lib/python3.6/site-packages/xopen-0.3.2-py3.6.egg']
<class 'str'>
Traceback (most recent call last):
  File "/share/apps/anaconda3/bin/deeptools", line 11, in <module>
    main(args)
  File "/share/apps/anaconda3/lib/python3.6/site-packages/deeptools/deeptools_list_tools.py", line 75, in main
    process_args(args)
  File "/share/apps/anaconda3/lib/python3.6/site-packages/deeptools/deeptools_list_tools.py", line 67, in process_args
    args = parse_arguments().parse_args(args)
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 1730, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 1762, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 1968, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 1908, in consume_optional
    take_action(action, args, option_string)
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 1836, in take_action
    action(self, namespace, argument_values, option_string)
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 1020, in __call__
    parser.print_help()
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 2362, in print_help
    self._print_message(self.format_help(), file)
  File "/share/apps/anaconda3/lib/python3.6/argparse.py", line 2371, in _print_message
    file.write(message)
UnicodeEncodeError: 'ascii' codec can't encode character '\xed' in position 383: ordinal not in range(128)

1 个答案:

答案 0 :(得分:0)

最好的答案可以在test1_in_equilibrium<-(subset(alldata,Time>=time1 & FinalPopSize==size)$Param)的{​​{1}}的源代码中找到。以下是与Python相关的文件的列表。

https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz

这是与LC_ALL=C相关的文件的列表。

 Python-3.7.3]$ find . -type f -exec grep -l "LC_ALL=C" {} \;
./Makefile.pre.in
./configure
./Misc/NEWS
./Lib/uuid.py
./Lib/test/test_c_locale_coercion.py