python 读写.tar.gz文件 -- UnicodeDecodeError


  在用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

  

参考资料:

python tar.gz格式压缩、解压

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM