在将主机的(Centos7)语言环境传递到python3 docker映像时遇到问题。即使我使用了下面链接中描述的建议,图像中也仅包含以下语言环境:
df.query('`Lost Flag`!=1')
Why does locale.getpreferredencoding() return 'ANSI_X3.4-1968' instead of 'UTF-8'?
我的Dockerfile具有:
>>> df = pd.DataFrame({'A': range(1, 6),
... 'B': range(10, 0, -2),
... 'C C': range(10, 5, -1)})
>>> df
A B C C
0 1 10 10
1 2 8 9
2 3 6 8
3 4 4 7
4 5 2 6
For columns with spaces in their name, you can use backtick quoting.
>>> df.query('B == `C C`')
A B C C
0 1 10 10
当我运行此命令时:
C
C.UTF-8
POSIX
它抛出此错误:
FROM python:3.7.5
ENV LC_ALL C.UTF-8
WORKDIR /data
ADD ./requirements.txt /data/requirements.txt
RUN pip install -r requirements.txt
COPY . /data
CMD [ "python3", "./test.py" ]
如果我设置
locale.setlocale(locale.LC_ALL,'ru_RU')
然后我得到:
Traceback (most recent call last):
File "./test.py", line 10, in <module>
locale.setlocale(locale.LC_ALL,'ru_RU')
File "/usr/local/lib/python3.7/locale.py", line 608, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
请说明如何将ru_RU语言环境添加到python图像中?
答案 0 :(得分:3)
对于基于Debian的docker映像我该怎么做:
FROM python:3.7.5
RUN apt-get update && \
apt-get install -y locales && \
sed -i -e 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales
ENV LANG ru_RU.UTF-8
ENV LC_ALL ru_RU.UTF-8
然后在python中
import locale
locale.setlocale(locale.LC_ALL,'ru_RU.UTF-8')