为什么在某些情况下需要为 Python 手动设置 LC_CTYPE [英] Why LC_CTYPE needs to be set manually for Python in some cases

查看:29
本文介绍了为什么在某些情况下需要为 Python 手动设置 LC_CTYPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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.

bugs.python.org

这篇关于为什么在某些情况下需要为 Python 手动设置 LC_CTYPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆