当我运行perl时,我得到警告:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

我该怎么解决呢?


当前回答

一如既往,细节决定成败。

在Mac OS X v10.7.5 (Lion)上,要修复一些Django错误,请在我的~/。bash_profile我已经设置:

export LANG=en_EN.UTF-8
export LC_COLLATE=$LANG
export LC_CTYPE=$LANG
export LC_MESSAGES=$LANG
export LC_MONETARY=$LANG
export LC_NUMERIC=$LANG
export LC_TIME=$LANG
export LC_ALL=$LANG

在很长一段时间里,我在使用Perl时都得到了这样的警告。

我的坏!我后来才意识到,我的系统是en_US.UTF-8! 我只是通过改变

export LANG=en_EN.UTF-8

to

export LANG=en_US.UTF-8

其他回答

我在Mac M1 Monterey上试过这些方法,但都不行。 禁用该消息的快速方法是: 打开终端->首选项->高级选项卡->取消勾选以在启动时设置区域环境变量

将LC_TYPE环境变量设置为默认的区域语言“C”将有助于消除此警告。

执行export LC_CTYPE="C",然后尝试执行perl命令。

附注:您需要在/etc/environment文件或/etc/default/locale文件中设置此变量以获得永久解决方案。

在Arch Linux中使用英国键盘和地区,我有以下错误:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.utf8"

在/etc/profile中导出我的locale并没有修复它。 不过,我确实通过编辑/etc/locale修复了这个问题同时启用en_US. gen。perl期望找到的Utf8语言环境,并运行local-gen。

(我使用的pac-manager使用AUR的一大堆perl模块,所以在我的特殊情况下重新安装perl将是一个麻烦。)

将缺失的地区添加到.bash_profile文件中:

echo "export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8">>~/.bash_profile

然后来源你的.bash_profile文件:

source ~/.bash_profile

对于Ubuntu Server和Debian:

不需要在bashrc中创建导出或处理dpkg-reconfigure。

只需将/etc/default/locale的内容替换为:

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8