UnicodeDecodeError:"charmap"编解码器无法解码位置X的字节0x9d:字符映射为< undefined> [英] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to <undefined>

查看:139
本文介绍了UnicodeDecodeError:"charmap"编解码器无法解码位置X的字节0x9d:字符映射为< undefined>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过pip安装 StringGenerator 时,系统提示我出现此错误:

When I'm trying to install StringGenerator with pip, I am prompted with this error:

C:\Users\Administrator> pip install StringGenerator

Collecting StringGenerator 
Using cached StringGenerator-0.3.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-build-mdvrj2cf\StringGenerator\setup.py", line 7, in <module>
    long_description = file.read()
  File "c:\users\administrator\appdata\local\programs\python\python36-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1264: character maps to <undefined>

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-build-mdvrj2cf\StringGenerator\

推荐答案

问题是在安装过程中读取README.txt时引起的.在Windows中,默认编码为cp1252,但是该自述文件很可能使用UTF8编码.

The problem is caused during the setup process when reading README.txt. In Windows, the default encoding is cp1252, but that readme file is most likely encoded in UTF8.

该错误消息告诉您cp1252编解码器无法解码字节0x9D的字符.浏览自述文件​​时,发现以下字符:(也称为"RIGHT DOUBLE QUOTATION MARK"),其字节为0xE2 0x80 0x9D ,其中包括有问题的字节.

The error message tells you that cp1252 codec is unable to decode the character with the byte 0x9D. When I browsed through the readme file, I found this character: " (also known as: "RIGHT DOUBLE QUOTATION MARK"), which has the bytes 0xE2 0x80 0x9D, which includes the problematic byte.

您可以做的是:

  1. 此处
  2. 下载软件包
  3. 解压缩程序包
  4. 打开setup.py
  5. 更改以下内容:
  1. Download the package here
  2. Decompress the package
  3. Open setup.py
  4. Change the following:

发件人:

with open('README.txt') as file:
    long_description = file.read()

更改为:

with open('README.txt', encoding="utf8") as file:
    long_description = file.read()

这将使用正确的编码打开文件.

This will open the file with the proper encoding.

或者您可以完全删除这两行,也可以在setup()内部的第18行删除long_description=long_description,.

Or you can remove these two line altogether and also remove long_description=long_description, at line 18 inside setup().

  1. 在控制台中,运行python setup.py install
  2. 您完成了!


由于setup.py脚本中没有实际的设置,因此您可以直接从 GitHub ,该软件包仍应正常运行.


Since there's no actual setup in the setup.py script, you can just directly clone the source folder from GitHub, the package should still work properly.

这篇关于UnicodeDecodeError:"charmap"编解码器无法解码位置X的字节0x9d:字符映射为&lt; undefined&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆