[英]UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to <undefined>
When I'm trying to install StringGenerator<\/a> with pip, I am prompted with this error:当我尝试使用 pip 安装
StringGenerator<\/a>时,系统提示我以下错误:
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\
The problem is caused during the setup process when reading README.txt
.问题是在设置过程中读取
README.txt
。 In Windows, the default encoding is cp1252, but that readme file is most likely encoded in UTF8.在 Windows 中,默认编码为 cp1252,但该自述文件很可能以 UTF8 编码。
The error message tells you that cp1252 codec is unable to decode the character with the byte 0x9D.错误消息告诉您 cp1252 编解码器无法解码字节为 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.当我浏览自述文件时,我发现了这个字符:
”
(也称为:“右双引号”),其中包含字节 0xE2 0x80 0x9D ,其中包括有问题的字节。
What you can do is:你可以做的是:
From:来自:
with open('README.txt') as file:
long_description = file.read()
Change into:改成:
with open('README.txt', encoding="utf8") as file:
long_description = file.read()
This will open the file with the proper encoding.这将使用正确的编码打开文件。
Or you can remove these two line altogether and also remove long_description=long_description,
at line 18 inside setup()
.或者,您可以完全删除这两行并删除
long_description=long_description,
位于setup()
内的第 18 行。
python setup.py install
python setup.py install
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.由于 setup.py 脚本中没有实际设置,您可以直接从GitHub克隆源文件夹,该包应该仍然可以正常工作。
只需在“open('path', here)”中添加encoding="utf8"
" 即可。
with open('path to csv file', encoding="utf8") as csv_file:
Go to https://pypi.python.org/pypi/StringGenerator/0.3.0 and download the latest version (or source in this case), extract the .gz file and then the .tar file.转到https://pypi.python.org/pypi/StringGenerator/0.3.0并下载最新版本(或本例中的源),解压 .gz 文件,然后解压 .tar 文件。
Next go in StringGenerator-0.2.0
folder and open a terminal and run:接下来进入
StringGenerator-0.2.0
文件夹并打开终端并运行:
python setup.py build
python setup.py install
Or from PowerShell run:或者从 PowerShell 运行:
python ./setup.py build
python ./setup.py install
I also had this problem with a pip install<\/code> on a Windows version of python.
我在 Windows 版本的 python 上
pip install<\/code>时也遇到了这个问题。
The solution is to set the following environment variable:
解决方案是设置以下环境变量:
PYTHONUTF8=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.