【问题标题】:Encoding error when installing Keras on Windows 10在 Windows 10 上安装 Keras 时出现编码错误
【发布时间】:2018-04-29 22:11:41
【问题描述】:

我正在尝试在 Windows 10 上安装 Keras。我按此特定顺序安装了 Visual Studio 2015 Community Edition、CUDA 8.0、它的第二个补丁、cuDNN 6.0、PyCharm、Anaconda、Python 3.6.3。 我安装了tensorflow-gpu。 我将\path-to\Python\Python36\bin 添加到PATH 环境变量和NVIDIA 文件夹中。 Tensorflow 在 shell 中工作,但不是在 Anaconda 提示符下工作。 当我尝试使用 PowerShell 中的pip install keras 安装 Keras 时,出现以下错误。

    PS C:\Users\myusr> pip install keras
    Collecting keras
      Downloading Keras-2.1.1-py2.py3-none-any.whl (302kB)
        100% |████████████████████████████████| 307kB 553kB/s
    Collecting pyyaml (from keras)
      Downloading PyYAML-3.12.tar.gz (253kB)
        100% |████████████████████████████████| 256kB 553kB/s
    Collecting scipy>=0.14 (from keras)
      Downloading scipy-1.0.0-cp36-none-win_amd64.whl (30.8MB)
        100% |████████████████████████████████| 30.8MB 41kB/s
    Requirement already satisfied: six>=1.9.0 in c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages (from keras)
    Requirement already satisfied: numpy>=1.9.1 in c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages (from keras)
    Building wheels for collected packages: pyyaml
      Running setup.py bdist_wheel for pyyaml ... error
      Failed building wheel for pyyaml
      Running setup.py clean for pyyaml
    Failed to build pyyaml
    Installing collected packages: pyyaml, scipy, keras
      Running setup.py install for pyyaml ... error
    Exception:
    Traceback (most recent call last):
      File "c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
        return s.decode(sys.__stdout__.encoding)
            UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 76: invalid start byte

            During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages\pip\basecommand.py", line 215, in main
        status = self.run(options, args)
      File "c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages\pip\commands\install.py", line 342, in run
        prefix=options.prefix_path,
      File "c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
        **kwargs
      File "c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_install.py", line 878, in install
        spinner=spinner,
      File "c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
        line = console_to_str(proc.stdout.readline())
      File "c:\users\myusr\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
        return s.decode('utf_8')
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 76: invalid start byte

我能做什么?

【问题讨论】:

  • 尝试单独安装pyyaml,看看会不会报同样的错误。 $ pip install pyyaml
  • 同时尝试更新您的 setuptools:$ pip install --upgrade setuptools --ignore-installed
  • 谢谢。错误输出还是一样,还是不行!
  • 您的操作系统使用什么语言?

标签: python windows tensorflow keras


【解决方案1】:

在我的 Windows 10 机器上安装 Keras 时,我遇到了完全相同的情况。

1) 第一步是成功安装 pyyaml,它与 easy_install 配合得很好,并且没有 UnicodeDecodeError 出现

easy_install pyyaml

2) 再次尝试安装 Keras

pip install keras

3) 您可能会收到有关缓存的 Keras 安装文件的奇怪错误:

zipfile.BadZipFile: Bad CRC-32 for file 'tensorflow-1.8.0.data/purelib/tensorflow/python/_pywrap_tensorflow_internal.pyd'

只需添加 no-cache 指令

pip install --no-cache-dir keras

【讨论】:

    【解决方案2】:

    这来自 pyyaml 模块。基于从版本 3.6 Python for Windows 开始使用 UTF-8 作为其控制台 IO 的事实,它会导致错误。在运行子进程的情况下,它认为子进程的输出也将是 UTF-8 ......事实并非如此。

    有 3 种方法可以解决此问题:

    1. 使用 Python
    2. 使用 locale.getpreferredencoding(False) 进行编码
    3. 从 cmd/powershell 运行命令: chcp 。它将显示系统默认代码,例如 936。打开 Lib/site-package/pip/compat/init.py 并在第 76 行附近更改

      return s.decode('utf_8')
      

      return s.decode('cp936')
      

    【讨论】:

    • 英语/意大利语。使用选项#2 是否有任何缺点(不仅在 python 中,在系统方面也是如此)?谢谢,我会尽快尝试
    • 没有任何我会知道:) 你没有设置,只是得到。
    • 我使用了方法1,效果很好。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 2017-02-20
    • 2017-03-21
    • 1970-01-01
    相关资源
    最近更新 更多