pip install – locale.Error:不支持的语言环境设置

完整的堆栈跟踪:

➜ ~ pip install virtualenv Traceback (most recent call last): File "/usr/bin/pip", line 11, in <module> sys.exit(main()) File "/usr/lib/python3.4/site-packages/pip/__init__.py", line 215, in main locale.setlocale(locale.LC_ALL, '') File "/usr/lib64/python3.4/locale.py", line 592, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting 

在同一台服务器上,我以前运行pip install virtualenv ,当时是python 2.7.x。

现在,我刚刚使用curl https://bootstrap.pypa.io/get-pip.py | python3.4安装了python3.4 curl https://bootstrap.pypa.io/get-pip.py | python3.4 curl https://bootstrap.pypa.io/get-pip.py | python3.4

 ➜ ~ pip --version pip 8.1.1 from /usr/lib/python3.4/site-packages (python 3.4) 

pip uninstall virtualenv也会抛出相同的错误

尝试一下:

 $ export LC_ALL=C 

这是我的locale设置:

 $ locale LANG=en_US.UTF-8 LANGUAGE= 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 

Python2.7

  $ uname -a Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux $ python --version Python 2.7.9 $ pip --version pip 8.1.1 from /usr/local/lib/python2.7/dist-packages (python 2.7) $ unset LC_ALL $ pip install virtualenv Traceback (most recent call last): File "/usr/local/bin/pip", line 11, in <module> sys.exit(main()) File "/usr/local/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main locale.setlocale(locale.LC_ALL, '') File "/usr/lib/python2.7/locale.py", line 579, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting $ export LC_ALL=C $ pip install virtualenv Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.7/dist-packages 

有人可能会觉得它有用。 您可以将该语言环境设置放在通常位于主目录中的.bashrc文件中。
只需在.bashrc中添加这个命令:
export LC_ALL=C
然后键入source .bashrc
现在你不需要每次手动调用这个命令,例如通过ssh连接。

运行以下命令(它将工作):

 export LC_ALL="en_US.UTF-8" export LC_CTYPE="en_US.UTF-8" sudo dpkg-reconfigure locales 

虽然您可以设置导出envvariables的语言环境,但每次启动会话时都必须这样做。 以这种方式设置语言环境将永久解决问题:

 sudo apt-get install apt-transport-https locales sudo wget sudo locale-gen en_US.UTF-8 sudo echo "LANG=en_US.UTF-8" > /etc/default/locale