在安裝LunarSolarConverter第三方庫時提示:
File "<string>", line 1, in <module> File "C:\Users\Administrator\AppData\Local\Temp\pip-install-wr4z978d\Lunar
SolarConverter\setup.py", line 15, in <module>
long_description = f.read() UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 65: illeg
al multibyte sequence ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check th e logs for full command output.
根據提示信息,應該是文件讀取中涉及到了中文。下載了LunarSolarConverter-1.1.0.tar.gz到本地並解壓,查看其中的setup.py文件,其中14,15行:
with open('README.rst') as f: long_description = f.read()
問題應該出在了14行 open 這個函數,作者應該在其后增加 encoding='UTF-8' ,確保數據讀取無誤。
既然定位到了問題,就趕緊修改驗證下吧。
修改后的代碼:
with open('README.rst', encoding='UTF-8') as f: long_description = f.read()
因為修改了文件內容,所以我們只好進行本地化安裝,代碼: python setup.py install
運行結果:
Installed f:\python38\lib\site-packages\lunarsolarconverter-1.1.0-py3.8.egg Processing dependencies for LunarSolarConverter==1.1.0 Finished processing dependencies for LunarSolarConverter==1.1.0
安裝成功,收工。
==========
續:
經過看作者在GitHub上的項目,作者已經發現並修改了這個bug,但是在pypi上並未更新。故,這篇文章先留着。