通过pip安装SQLAlchemy时出现UnicodeDecodeError

时间:2017-01-10 10:19:09

标签: python python-3.x pip

我试图通过pip安装SQLAlchemy。但是,我失败了。

我的操作系统是Windows 10中文版,我使用的是Python 3.6.0。

我在互联网上搜索了我的问题并得到了许多解决方案,我说我可以将sys.setdefaultencoding添加到某个文件中。但是我使用的是Python3。

我还发现issue on Github这似乎是我的问题。但是将我的代码页更改为866或65001根本不起作用......

以下是信息:

C:\Users\59740>pip install SQLAlchemy
Collecting SQLAlchemy
  Using cached SQLAlchemy-1.1.4.tar.gz
Installing collected packages: SQLAlchemy
  Running setup.py install for SQLAlchemy ... error
Exception:
Traceback (most recent call last):
  File "c:\program files\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 0xb6 in position 34: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\program files\python36\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "c:\program files\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "c:\program files\python36\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "c:\program files\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "c:\program files\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 0xb6 in position 34: invalid start byte

2 个答案:

答案 0 :(得分:1)

打开\ python36 \ lib \ site-packages \ pip \ compat__init __。py 75 return s.decode(' utf_8 ')更改为

  

返回s.decode(' cp936 ')

其他: chcp cmd显示当前代码页

答案 1 :(得分:0)

我解决了这个问题,在“\ python36 \ lib \ site-packages \ pip \ compat__init __。py”中更改了75行(感谢之前的评论) return s.decode('latin1')