UnicodeDecodeError:"charmap"编解码器无法解码位置X的字节0x9d:字符映射为< undefined> [英] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to <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.
您可以做的是:
- 在此处 下载软件包
- 解压缩程序包
- 打开setup.py
- 更改以下内容:
- Download the package here
- Decompress the package
- Open setup.py
- 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()
.
- 在控制台中,运行
python setup.py install
- 您完成了!
由于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:字符映射为< undefined>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!