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

标签 python python-3.x unicode docker

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

为了部署,我想将 Docker 与位于我的 Github 存储库根目录中的 Dockerfile 一起使用(您可以查看)。所以,当我执行“docker build”时。我在这一行收到错误:

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

从控制台登录:

  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 做了一些奇怪的事情来定位它的版本号——它打开了一个源文件,其中包含非 ascii 字符,但没有声明编码。在 Python 3 中,这将使用您的区域设置,在您的情况下,它似乎已损坏或设置为 LANG=C|POSIX

您有以下选择:

  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
    

关于python - 构建 Docker 容器时 python3 中的神秘 UnicodeDecodeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36398996/

相关文章:

python - 如何用渐变填充 matplotlib 条形图?

python - 两个数据框的差异

python - ORA-01036 : illegal variable name/number (cx_Oracle)

python - 如何从元组中随机选择一个字符串并随机插入文本中的每一行?

javascript - Uncaught Error : INVALID_CHARACTER_ERR: DOM Exception 5

python - setup.py 中的 pip -t 相当于什么?

python - 如何使用 RotatingFileHandler 设置日志记录?

python - Python中的饼图动画

string - [Char] 和 [Word8] 之间转换的最佳方式?

javascript - 排序在非字母(即亚洲)语言中意味着什么?