在Windows 10上安装Keras时出现编码错误 [英] Encoding error when installing Keras on Windows 10
问题描述
我试图在Windows 10上安装Keras.我已按照此特定顺序安装了Visual Studio 2015社区版CUDA 8.0,第二个补丁cuDNN 6.0,PyCharm,Anaconda,Python 3.6.3.
我安装了tensorflow-gpu
.
我在PATH
环境变量和NVIDIA文件夹中添加了\path-to\Python\Python36\bin
. Tensorflow在shell上有效,但在Anaconda提示符下无效.
当我尝试使用PowerShell中的pip install keras
安装Keras时,出现以下错误.
I am trying to install Keras on Windows 10. I installed Visual Studio 2015 Community Edition, CUDA 8.0, its second patch, cuDNN 6.0, PyCharm, Anaconda, Python 3.6.3 in this specific order.
I installed tensorflow-gpu
.
I added \path-to\Python\Python36\bin
to the PATH
environment variable, and for the NVIDIA folders. Tensorflow works from the shell but not from the Anaconda prompt.
When I try to install Keras by using pip install keras
from PowerShell I get the following error.
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模块.基于以下事实:从Windows的3.6版开始,Python for Windows使用UTF-8作为其控制台IO,这会导致错误.如果运行一个子进程,它认为该子进程的输出也将是UTF-8 ...,情况并非如此.
This is coming from pyyaml module. Based on the fact that from version 3.6 Python for Windows is using UTF-8 for it's console IO it leads to errors. In case of running a subprocess, it thinks that the output from subprocess will be also UTF-8... which is not the case.
有3种方法可以解决此问题:
There are 3 ways to fix this:
- 使用Python< 3.6(例如3.5.2)
- 使用locale.getpreferredencoding(False)进行编码
-
从cmd/powershell运行命令:chcp.它将显示系统默认代码,例如936.打开Lib/site-package/pip/compat/ init .py 并围绕第76行发生变化
- Use Python < 3.6 (e.g. 3.5.2)
- Use locale.getpreferredencoding(False) for the encoding
Run a command from cmd/powershell: chcp . It will show the system default code, for example 936. Open Lib/site-package/pip/compat/init.py and around line 76 change
return s.decode('utf_8')
到
return s.decode('cp936')
这篇关于在Windows 10上安装Keras时出现编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!