Questions tagged [pickle]

Pickle is an object serialization module for Python. Use this tag together with the Python tag for questions related to storing or loading objects with Pickle.

Pickle provides a powerful set of tools for serializing and de-serializing Python objects.

4936 questions
91
votes
4 answers

Python 3.7 Error: Unsupported Pickle Protocol 5

I'm trying to restore a pickled config file from RLLib (json didn't work as shown in this post), and getting the following error: config = pickle.load(open(f"{path}/params.pkl",…
hubbs5
  • 1,235
  • 1
  • 12
  • 22
88
votes
5 answers

How to pickle yourself?

I want my class to implement Save and Load functions which simply do a pickle of the class. But apparently you cannot use 'self' in the fashion below. How can you do this? self = cPickle.load(f) cPickle.dump(self,f,2)
user317033
86
votes
2 answers

Python pickle protocol choice?

I an using python 2.7 and trying to pickle an object. I am wondering what the real difference is between the pickle protocols. import numpy as np import pickle class Data(object): def __init__(self): self.a = np.zeros((100, 37000, 3),…
Cobry
  • 4,348
  • 8
  • 33
  • 49
84
votes
3 answers

installing cPickle with python 3.5

This might be silly but I am unable to install cPickle with python 3.5 docker image Dockerfile FROM python:3.5-onbuild requirements.txt cpickle When I try to build the image $ docker build -t sample . Sending build context to Docker daemon 3.072…
kampta
  • 4,748
  • 5
  • 31
  • 51
82
votes
5 answers

Unable to load files using pickle and multiple modules

I'm trying to create a user system, which uses a setting and Gui module, and when the GUI module requests for the file to load up using pickle, I keep getting an attribute error. this is from the settings module: import pickle import hashlib class…
Inthu
  • 1,009
  • 1
  • 8
  • 16
82
votes
6 answers

Can Python pickle lambda functions?

I have read in a number of threads that Python pickle/cPickle cannot pickle lambda functions. However the following code works, using Python 2.7.6: import cPickle as pickle if __name__ == "__main__": s = pickle.dumps(lambda x, y: x+y) f =…
Lars
  • 1,869
  • 2
  • 14
  • 26
73
votes
3 answers

What is the HTTP "content-type" to use for a blob of bytes?

What is the HTTP "content-type" to use when returning a blob of bytes in response to a client's GET request? In this case, the information payload is an object serialized using Python's Pickle library.
Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
72
votes
11 answers

What causes the error "_pickle.UnpicklingError: invalid load key, ' '."?

I'm trying to store 5000 data elements on an array. This 5000 elements are stored on an existinng file (therefore it's not empty). But I'm getting an error. IN: def array(): name = 'puntos.df4' m = open(name, 'rb') v = []*5000 …
Xcecution
  • 937
  • 1
  • 9
  • 14
71
votes
1 answer

What's the exact usage of __reduce__ in Pickler

I know that in order to be picklable, a class has to overwrite __reduce__ method, and it has to return string or tuple. How does this function work? What the exact usage of __reduce__? When will it been used?
oyjh
  • 1,248
  • 1
  • 9
  • 20
71
votes
5 answers

How to pickle a namedtuple instance correctly

I'm learning how to use pickle. I've created a namedtuple object, appended it to a list, and tried to pickle that list. However, I get the following error: pickle.PicklingError: Can't pickle : it's not found as __main__.P I…
Dirty Penguin
  • 4,212
  • 9
  • 45
  • 69
70
votes
6 answers

Hitting Maximum Recursion Depth Using Pickle / cPickle

The background: I'm building a trie to represent a dictionary, using a minimal construction algorithm. The input list is 4.3M utf-8 strings, sorted lexicographically. The resulting graph is acyclic and has a maximum depth of 638 nodes. The first…
danben
  • 80,905
  • 18
  • 123
  • 145
68
votes
7 answers

Understanding Pickling in Python

I have recently got an assignment where I need to put a dictionary (where each key refers to a list) in pickled form. The only problem is I have no idea what pickled form is. Could anyone point me in the right direction of some good resources to…
Spencer
  • 21,348
  • 34
  • 85
  • 121
68
votes
5 answers

ImportError: No module named 'pandas.core.internals.managers'; 'pandas.core.internals' is not a package

When I tried to read a pickle file that saved by a former version of pandas, it yielded an ImportError. ImportError: No module named 'pandas.core.internals.managers'; 'pandas.core.internals' is not a package There was no hit on stackoverflow so…
Fatih1923
  • 2,665
  • 3
  • 21
  • 28
67
votes
7 answers

Python 3 - Can pickle handle byte objects larger than 4GB?

Based on this comment and the referenced documentation, Pickle 4.0+ from Python 3.4+ should be able to pickle byte objects larger than 4 GB. However, using python 3.4.3 or python 3.5.0b2 on Mac OS X 10.10.4, I get an error when I try to pickle a…
RandomBits
  • 4,194
  • 1
  • 17
  • 30