UnpicklingError:在utils.file

时间:2018-05-19 05:26:00

标签: python python-2.7

我面临这个错误:

文件" C:\ Python27 \ lib \ site-packages \ gensim \ utils.py",第1334行,在unpickle     return _pickle.load(f,encoding =' latin1')

UnpicklingError:找不到MARK

而我的utils.py代码是:

with smart_open(fname, 'rb') as f:
    f.seek(0)
    # Because of loading from S3 load can't be used (missing readline in smart_open)
    if sys.version_info > (3, 0):
        return _pickle.load(f, encoding='latin1')
    else:
        return _pickle.loads(f.read())



def pickle(obj, fname, protocol=2):
    """Pickle object `obj` to file `fname`.

    Parameters
    ----------
    obj : object
        Any python object.
    fname : str
        Path to pickle file.
    protocol : int, optional
        Pickle protocol number, default is 2 to support compatible across python 2.x and 3.x.

    """
    with smart_open(fname, 'wb') as fout:  # 'b' for binary, needed on Windows
        _pickle.dump(obj, fout, protocol=protocol)

任何人都请帮助我,我几天都在受苦......

1 个答案:

答案 0 :(得分:0)

您可能正在尝试加载已在Python 3中训练和保存的模型,但您使用的是Python 2.请参阅

https://github.com/RaRe-Technologies/gensim/issues/853