简体   繁体   English

类型错误:加载 pickle 文件时需要 integer(获取类型字节)

[英]TypeError: an integer is required (got type bytes) while loading the pickle file

It throws below error while loading the pickle file.加载 pickle 文件时抛出以下错误。 return types.CodeType( TypeError: an integer is required (got type bytes) return types.CodeType( TypeError: 需要一个 integer(得到类型字节)

if __model is None:

    with open('banglore_home_prices_model_2.pickle', 'rb') as f:
        __model = pickle.load(f) - > Error is raised for this line of code
    print(__model)

Looks like the error is actually raised by cloudpickle, Not sure this is raised bcz of conflicting versions.if someone have come across this issue, let me know what helped you to fix this issue.看起来错误实际上是由 cloudpickle 引发的,不确定这是冲突版本引发的 bcz。如果有人遇到过这个问题,请告诉我是什么帮助你解决了这个问题。
I have created virtual environment for this project and installed the requirements.我已经为这个项目创建了虚拟环境并安装了要求。 I'am using python3 version.我正在使用 python3 版本。

you are reading file as "rb" mode as it opens the file in binary format for reading您正在以“rb”模式读取文件,因为它opens the file in binary format for reading

  • try this试试这个
import pickle
pickle.load('banglore_home_prices_model_2.pickle')
  • or load it using joblib或者使用joblib加载它
from joblib import load
model = load('banglore_home_prices_model_2.pickle')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:使用pickle需要一个整数(得到类型_io.BufferedWriter) - TypeError: an integer is required (got type _io.BufferedWriter) using pickle TypeError:需要一个类似字节的对象,而在用pickle加载时不是&#39;str&#39; - TypeError: a bytes-like object is required, not 'str' while loading with pickle TypeError:运行服务器时需要一个 integer(获取类型字节) - TypeError: an integer is required (got type bytes) when running server 类型错误:导入 sklearn 时需要一个 integer(获取类型字节) - TypeError: an integer is required (got type bytes) when importing sklearn pickle.dump(stats, items, outfile) TypeError: 需要一个 integer (got type _io.BufferedWriter) - pickle.dump(stats, items, outfile) TypeError: an integer is required (got type _io.BufferedWriter) 尝试使用“pyinstaller”<scriptname.py> ”并得到“TypeError:需要一个 integer(获取类型字节)”</scriptname.py> - Tried to use “pyinstaller <scriptname.py>” and got “TypeError: an integer is required (got type bytes)” TypeError:写入文件需要 integer(获取类型 str) - TypeError: an integer is required (got type str) for writing to file 类型错误:在 Python 中打开文件时需要 integer(获取类型 str) - TypeError: an integer is required (got type str) when opening file in Python 在 Google colab 中安装 PySpark 时出错 - 类型错误:需要 integer(获取类型字节) - Error installing PySpark in Google colab - TypeError: an integer is required (got type bytes) Python TypeError:整数是必需的(got类型列表) - Python TypeError: an integer is required (got type list)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM