Unpickling python objects with a changed module path

后端 未结 4 1746
梦如初夏
梦如初夏 2020-12-14 02:29

I\'m trying to integrate a project Project A built by a colleague into another python project. Now this colleague has not used relative imports in his code but

4条回答
  •  遥遥无期
    2020-12-14 02:53

    One possible solution is to directly edit the pickle file (if you have access). I ran into this same problem of a changed module path, and I had saved the files as pickle.HIGHEST_PROTOCOL so it should be binary in theory, but the module path was sitting at the top of the pickle file in plain text. So I just did a find replace on all of the instances of the old module path with the new one and voila, they loaded correctly.

    I'm sure this solution is not for everyone, especially if you have a very complex pickled object, but it is a quick and dirty data fix that worked for me!

提交回复
热议问题