为什么在某些情况下需要为 Python 手动设置 LC_CTYPE [英] Why LC_CTYPE needs to be set manually for Python in some cases
问题描述
我正在尝试使用 Django 的管理文档.我遵循了this教程并安装了docutils强>.安装后,我通过 python manage.py runserver 运行 Django 开发服务器并得到错误 unknown locale: UTF-8.
I am trying to use Django's Admin documentation. I followed this tutorial and installed docutils. After installing I run Django development server through python manage.py runserver and get error unknown locale: UTF-8.
我按照这个问题中的说明解决了问题:
I solved issue as explained in this question:
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
但我的问题是:这个问题的根源是什么?docutils 似乎与 Python 或其他东西有一些兼容性问题?
But my question is: What is origin of this problem? It seems docutils has some compatibility problem with Python or something else?
推荐答案
这是个老问题,但在 OSX El Capitan 上仍然发生.这个问题的根源在于 Python 假设 locale 环境变量的格式为 language_region.encoding.这个假设对 Python 来说是严格的,因为当有效的语言和区域对不可用时,OSX 默认使用 UTF-8.
This is old issue, but still happening on OSX El Capitan. The origin of this problem is that Python assumes locale environment variable to be in format of language_region.encoding. This assumption is strict on Python's part as OSX defaults to UTF-8 when valid language and region pair is not available.
这篇关于为什么在某些情况下需要为 Python 手动设置 LC_CTYPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!