当我尝试使用 pip 安装 StringGenerator 时,系统会提示我以下错误:
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 0x800x9D,其中包括有问题的字节。
你能做的是:
来自:
with open('README.txt') as file:
long_description = file.read()
更改为:
with open('README.txt', encoding="utf8") as file:
long_description = file.read()
这将以正确的编码打开文件。
或者您可以完全删除这两行,并删除
long_description=long_description,
内第18行的setup()
。
python setup.py install
由于 setup.py 脚本中没有实际设置,您可以直接从 GitHub 克隆源文件夹,该包应该仍然可以正常工作。
只需在“open('path', here)”中添加
encoding="utf8"
即可。
with open('path to csv file', encoding="utf8") as csv_file:
我在 Windows 版本的 python 上也遇到了这个问题。解决方案是设置以下环境变量:
pip install
如果影响您的正常开发,您可以在安装完成后取消设置。
时遇到了类似的问题。我已经下载了该软件包,解压了 tar.gz 并清空了 Readme.md 文件(导致错误的是文件中的一些汉字)。之后我替换了 tar.gz 中新的空 Readme.md,并使用 python ./setup.py build
python ./setup.py install
安装它,没有任何问题。