简体   繁体   English

构建基于python的docker的Locale.Error

[英]Locale.Error with building python based docker

I am new to docker and would appreciate if someone can help me get rid of this error while building the docker image. 我是Docker的新手,如果有人可以帮助我摆脱构建Docker映像时出现的错误,我将不胜感激。 It is giving some kind of locale error. 它给出了某种区域设置错误。 How can I get rid of this error ? 如何摆脱这个错误?

Collecting pip
Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
Collecting setuptools
Downloading setuptools-20.3.1-py2.py3-none-any.whl (508kB)
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-8.1.1 setuptools-20.3.1 wheel-0.29.0
+ pip install --no-cache-dir --upgrade pip==8.0.2
Traceback (most recent call last):
File "/usr/bin/pip", line 11, in 
sys.exit(main())
File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 215, in main
locale.setlocale(locale.LC_ALL, '')
File "/usr/lib64/python2.7/locale.py", line 547, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
The command '/bin/sh -c set -ex && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" && curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 && pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION' returned a non-zero code: 1

This is my Dockerfile: 这是我的Dockerfile:

FROM mybase:1.0.7

RUN set -x \
&& yum install -y python-devel libffi-devel python-cffi \
&& yum clean all

ENV LANG C.UTF-8

ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF

ENV PYTHON_VERSION 2.7.11

ENV PYTHON_PIP_VERSION 8.0.2

RUN set -ex \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
&& curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 \
&& pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION

RUN pip install --no-cache-dir virtualenv

CMD ["python2"]

The locale.setlocale docs say the locale should be valid. locale.setlocale文档说该locale应该有效。 If an empty string is passed, the LANG variable is used to set the locale. 如果传递了空字符串,则使用LANG变量设置语言环境。 This error is probably caused because your LANG is not a supported locale 此错误可能是由于您的LANG不是受支持的语言环境引起的

In your docker script, you set LANG to C.UTF-8 . C.UTF-8脚本中,将LANG设置为C.UTF-8 It looks like C.UTF-8 is not a supported locale in glibc and I am guessing hence in Python (See this and this ). 看起来glibc中不支持C.UTF-8语言环境,因此我猜想是在Python中(请参阅thisthis )。

You can set your LANG to a supported type like en_US.UTF-8 (The default on my computer). 您可以将LANG设置为受支持的类型,例如en_US.UTF-8 (计算机上的默认设置)。

On Python-2.6, I get the following results 在Python-2.6上,我得到以下结果

Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'en_US.utf8'
>>> locale.setlocale(locale.LC_ALL, "C.UTF-8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/locale.py", line 513, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
>>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
'en_US.UTF-8'
>>> locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")
'de_DE.UTF-8'

You can view the locales available on your computer by running 您可以通过运行以下命令查看计算机上可用的语言环境

$ locale -a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM