pickle.load() - 类型错误:需要一个整数(得到类型字节)

时间:2021-05-04 12:33:20

标签: scikit-learn pickle python-3.8

使用 .pkl 加载 pickle.load() 文件时引发了 TypeError。实际上,以前它是带有 Python 3.7 的工作文件,但现在我使用的是 Python 3.8.9

Python 3.8.9
cloudpickle==1.6.0
scikit-learn==0.20.2

片段 -

import pickle


with open('some_model.pkl', "rb") as f:
    pickle.load(f, **{"encoding": "latin1"})

异常-

Traceback (most recent call last):
  File "/home/phenix/common_utils.py", line 66, in <module>
    pickle.load(f, **{"encoding": "latin1"})
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/__init__.py", line 64, in <module>
    from .base import clone
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/base.py", line 13, in <module>
    from .utils.fixes import signature
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 14, in <module>
    from . import _joblib
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/utils/_joblib.py", line 22, in <module>
    from ..externals import joblib
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/__init__.py", line 119, in <module>
    from .parallel import Parallel
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/parallel.py", line 28, in <module>
    from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 22, in <module>
    from .executor import get_memmapping_executor
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/executor.py", line 14, in <module>
    from .externals.loky.reusable_executor import get_reusable_executor
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/externals/loky/__init__.py", line 12, in <module>
    from .backend.reduction import set_loky_pickler
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/externals/loky/backend/reduction.py", line 125, in <module>
    from sklearn.externals.joblib.externals import cloudpickle  # noqa: F401
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/__init__.py", line 3, in <module>
    from .cloudpickle import *
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py", line 167, in <module>
    _cell_set_template_code = _make_cell_set_template_code()
  File "/home/phenix/venv/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py", line 148, in _make_cell_set_template_code
    return types.CodeType(
TypeError: an integer is required (got type bytes)

0 个答案:

没有答案