在用pip install 安裝庫的時候,偶爾會出現編碼錯誤(如:UnicodeDecodeError: 'gbk' codec can't decode byte),對此我們可先將包下載下來(一般為.tar.gz格式),然后修改其中的錯誤代碼,再執行本地安裝即可。
import tarfile
import os
#下載庫安裝包
pip download wlab
#庫包解壓縮與壓縮
def untar(fname, dirs):
t = tarfile.open(fname)
t.extractall(path = dirs)
def tar(fname):
t = tarfile.open(fname + ".tar.gz", "w:gz")
for root, dir, files in os.walk(fname):
print(root, dir, files)
for file in files:
fullpath = os.path.join(root, file)
t.add(fullpath)
t.close()
untar('wlab-1.1.5.tar.gz', '.') #'.'表示解壓到當前目錄,'./wlab',對解壓后文件修正
tar('wlab-1.1.5')
#安裝庫
pip install c:\users\epsoft\wlab-1.1.5.tar.gz
參考資料:
