在构buildDocker容器时python3中的Mysterious UnicodeDecodeError

我正在创build一个python 3应用程序。 https://github.com/Omrigan/TED-analysis

部署我想要在我的Github仓库的根目录中使用Docker和Dockerfile(你可以检查它)。 所以,当我做“dockerbuild造”。 我在这行上得到一个错误:

RUN pip3 install --upgrade -r /root/ted_talks/requirements.txt 

从控制台login:

  Collecting httpretty==0.8.10 (from smart-open>=1.2.1->gensim->-r /root/ted_talks/requirements.txt (line 4)) Downloading httpretty-0.8.10.tar.gz (41kB) Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-em459e9u/httpretty/setup.py", line 86, in <module> version=read_version(), File "/tmp/pip-build-em459e9u/httpretty/setup.py", line 46, in read_version finder.visit(ast.parse(local_file('httpretty', '__init__.py'))) File "/tmp/pip-build-em459e9u/httpretty/setup.py", line 78, in <lambda> open(os.path.join(os.path.dirname(__file__), *f)).read() File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 133: ordinal not in range(128) 

所以我该怎么做?

看来,httpretty做了一些时髦的东西来find它的版本号 – 它打开的源文件之一,其中包含非ASCII字符,没有声明一个编码。 在Python 3中,这将使用您的语言环境,在您的情况下,似乎已损坏或设置为LANG=C|POSIX

您有以下select:

  1. 下载httpretty-0.8.10,编辑httpretty/__init__.py并删除非ascii字符( ã )。
  2. 将您的语言环境设置为en_US.UTF-8
  3. 我看到httpretty 0.8.14引用了Python 3兼容。 尝试安装:

     pip3 install httpretty==0.8.14 

我有同样的问题。 原因是我select的语言环境(即en_US.utf8)没有安装。 安装这个区域解决了我的问题。

要设置区域设置:

 locale-gen en_US.utf8 dpkg-reconfigure locales 

并selecten_US.utf8作为您的默认语言环境