linux env LC_ALL=C确实改变了语言环境,但是它导致了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)发布于 2019-04-10 05:54:21
最好的答案可以在https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz的Python源代码中找到。以下是与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以下是与LC_ALL相关的文件列表。
Python-3.7.3]$ find . -type f -exec grep -l "LC_ALL" {} \;
./Doc/whatsnew/3.7.rst
./Doc/tutorial/stdlib2.rst
./Doc/using/cmdline.rst
./Doc/library/gettext.rst
./Doc/library/curses.rst
./Doc/library/locale.rst
./Doc/library/test.rst
./Modules/_decimal/tests/formathelper.py
./Modules/_localemodule.c
./Modules/main.c
./Makefile.pre.in
./configure
./Mac/BuildScript/build-installer.py
./Misc/HISTORY
./Misc/NEWS
./Lib/tkinter/filedialog.py
./Lib/gettext.py
./Lib/distutils/command/wininst-9.0-amd64.exe
./Lib/distutils/command/wininst-9.0.exe
./Lib/distutils/command/wininst-10.0-amd64.exe
./Lib/distutils/command/wininst-10.0.exe
./Lib/ctypes/util.py
./Lib/uuid.py
./Lib/locale.py
./Lib/test/test_io.py
./Lib/test/test_utf8_mode.py
./Lib/test/test_format.py
./Lib/test/test_cmd_line.py
./Lib/test/test_logging.py
./Lib/test/test_locale.py
./Lib/test/test_ssl.py
./Lib/test/test_sys.py
./Lib/test/test_builtin.py
./Lib/test/test__locale.py
./Lib/test/test_subprocess.py
./Lib/test/test_decimal.py
./Lib/test/test_time.py
./Lib/test/test_imaplib.py
./Lib/test/test_c_locale_coercion.py
./Lib/test/pickletester.py
./Lib/test/test_unicode.py
./Python/pylifecycle.c
./Python/frozenmain.chttps://stackoverflow.com/questions/50025219
复制相似问题