简体   繁体   English

"UnicodeDecodeError:“charmap”编解码器无法解码位置 X 中的字节 0x9d:字符映射到<undefined>"

[英]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:你可以做的是:

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

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 行。

  1. In console, run python setup.py install在控制台中,运行python setup.py install
  2. And you're done!你完成了!

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.

相关问题 Python-UnicodeDecodeError:“ charmap”编解码器无法解码位置1070的字节0x9d:字符映射到<undefined> - Python - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1070: character maps to <undefined> UnicodeDecodeError:“charmap”编解码器无法解码位置 2433 中的字节 0x9d:字符映射到<undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2433: character maps to <undefined> UnicodeDecodeError:“charmap”编解码器无法解码 position 1915 中的字节 0x9d:字符映射到<undefined></undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1915: character maps to <undefined> UnicodeDecodeError:“ charmap”编解码器无法解码位置2247中的字节0x9d:字符映射到<undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2247: character maps to <undefined> UnicodeDecodeError: &#39;charmap&#39; 编解码器无法解码位置 295 中的字节 0x9d:字符映射到<undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 295: character maps to <undefined> UnicodeDecodeError:“ charmap”编解码器无法解码位置1010494中的字节0x9d:字符映射到<undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1010494: character maps to <undefined> 如何修复:UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 5518: character maps to<undefined> 错误</undefined> - How to fix: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 5518: character maps to <undefined> error 如何修复错误 'UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 36188: character maps to<undefined> '</undefined> - How to fix the error 'UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 36188: character maps to <undefined>' 如何修复 &#39;&#39;UnicodeDecodeError: &#39;charmap&#39; codec can&#39;t decode byte 0x9d in position 29815: character maps to<undefined> &#39;&#39;? - How to fix ''UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 29815: character maps to <undefined>''? UnicodeDecodeError:“charmap”编解码器无法解码 position 中的字节 0x8d 121835:字符映射到<undefined></undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 121835: character maps to <undefined>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM