ValueError: unsupported pickle protocol: 3
出现该问题说明是在python2环境下想打开原本在python3下pickle保存的文件
解决这个问题的方式是:在原先python3环境下保存的时候改变pickle.dump()中protocol 参数为2
比如:
复制代码
1
2
3path = './file.pkl' with open(path,'wb') as f: pickle.dump(centers,f,protocol =2)
这样就可以在python2 环境下再打开,不报错:
复制代码
1
2
3
4path = './file.pkl' with open(path,'rb') as f: the_file = pickle.load(f) print(the_file)
最后
以上就是醉熏钢笔最近收集整理的关于python3的pickle保存pkl文件用python2打开出错的全部内容,更多相关python3内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复