当我尝试安装 StringGenerator 时使用 pip,系统提示我出现此错误:
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 编码的。
错误消息告诉您cp1252 编解码器无法解码字节为0x9D 的字符。当我浏览自述文件时,我发现了这个字符:”
(也称为:“右双引号”),它有字节 0xE2 0x80 0x9D,其中包括有问题的字节。
你可以做的是:
- 下载包here
- 解压包
- 打开setup.py
- 更改以下内容:
来自:
with open('README.txt') as file:
long_description = file.read()
变成:
with open('README.txt', encoding="utf8") as file:
long_description = file.read()
这将打开具有正确编码的文件。
或者您可以完全删除这两行,同时删除 setup()
中第 18 行的 long_description=long_description,
。
- 在控制台中,运行
python setup.py install
- 大功告成!
由于 setup.py 脚本中没有实际设置,您可以直接从 GitHub 克隆源文件夹。 ,包应该仍然可以正常工作。
关于python - Unicode解码错误: 'charmap' codec can't decode byte 0x9d in position X: character maps to <undefined>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49640513/