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

其他回答

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

在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

对我来说,在Ubuntu 16.04 (Xenial Xerus)上,以下工作:

root@host:~#locale-gen en_GB.UTF-8
root@host:~#localectl set-locale LANG=en_GB.UTF-8,LC_ALL=en_GB.UTF-8

然后重新启动…

以下是如何在Mac OS X v10.7 (Lion)或Cygwin (Windows 10)上解决这个问题:

在主机上的bashrc或bash_profile文件中添加以下代码行:

# Setting for the new UTF-8 terminal support in Lion
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

如果你使用Z shell (zsh),编辑文件zshrc:

# Setting for the new UTF-8 terminal support in Lion
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8
perl -e exit
sudo localedef -i en_US -f UTF-8 en_DE.UTF-8
#                                   DE = German
# Use your country code en lieu of  DE

# The second "perl" should then not complain any more
perl -e exit

localectl list-locales # Just make sure it is OK

导出变量

$ export LANGUAGE=en_US.UTF-8
$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LC_CTYPE=en_US.UTF-8

下一个运行

$ sudo locale-gen
$ sudo dpkg-reconfigure locales 

当您运行dpkg-reconfigure locale时,它会要求您选择locale,选择en_US。utf - 8。如果通过选择所有区域设置来运行此操作,则需要一些时间来配置。