构建Docker容器时python3中的神秘UnicodeDecodeError

Omr*_*gan 5 python unicode python-3.x docker

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

要进行部署,我想将Dockerfile与位于Github存储库根目录中的Dockerfile一起使用(您可以检查一下)。因此,当我执行“ docker build”时。我在这条线上出现错误:

RUN pip3 install --upgrade  -r /root/ted_talks/requirements.txt
Run Code Online (Sandbox Code Playgroud)

从控制台登录:

  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)
Run Code Online (Sandbox Code Playgroud)

所以我该怎么做?

Ala*_*ack 1

看起来 httpretty 做了一些奇怪的事情来定位它的版本号 - 它打开一个源文件,其中包含非 ascii 字符,而不声明编码。在 Python 3 中,这将使用您的语言环境,在您的情况下,该语言环境似乎已损坏或设置为LANG=C|POSIX.

\n\n

您有以下选择:

\n\n
    \n
  1. 下载httpretty-0.8.10,编辑httpretty/__init__.py并删除非ascii字符(\xc3\xa3)。
  2. \n
  3. 将您的区域设置设置为en_US.UTF-8
  4. \n
  5. 我看到 httpretty 0.8.14 引用了 Python 3 兼容。尝试安装:

    \n\n
    pip3 install httpretty==0.8.14\n
    Run Code Online (Sandbox Code Playgroud)
  6. \n
\n