pickle

pickle.PicklingError: Cannot pickle files that are not opened for reading

梦想的初衷 提交于 2019-12-07 07:11:31
问题 i'm getting this error while running pyspark job on dataproc. What could be the reason ? This is the stack trace of error. File "/usr/lib/python2.7/pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "/usr/lib/spark/python/lib/pyspark.zip/pyspark/cloudpickle.py", line 553, in save_reduce File "/usr/lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/usr/lib/python2.7/pickle.py", line 649, in save_dict self._batch_setitems(obj

Pickle Queue objects in python

爷,独闯天下 提交于 2019-12-07 06:45:55
问题 I have a class that uses a list of Queue objects. I need to pickle this class including the information saved in the queue objects. For example: import Queue import pickle class QueueTest(object): def __init__(self): self.queueList = [] def addQueue(self): q = Queue.Queue() q.put('test') self.queueList.append(q) obj = QueueTest() obj.addQueue() with open('pickelTest.dat','w') as outf: pickle.dump(obj,outf) returns the error raise TypeError, "can't pickle %s objects" % base.__name__ TypeError:

IO Error while storing data in pickle

老子叫甜甜 提交于 2019-12-07 06:13:49
问题 i have a following code in a python to store data in pickle , but i am getting IO Error [Errno 13] Permission denied: 'data.pkl' Code def SaveUserData(request): datalist={} datalist['empid']='127113' datalist['empname']='eric' datalist['empphone']='66335500' datalist['email']='eric.pk@moliba.com' output = open('data.pkl', 'wb') pickle.dump(datalist, output) output.close() data = simplejson.dumps(datalist, indent=4) return HttpResponse(data,mimetype='application/javascript') 回答1: Well i

How to find source of error in Python Pickle on massive object

偶尔善良 提交于 2019-12-07 05:02:24
问题 I've taken over somebody's code for a fairly large project. I'm trying to save program state, and there's one massive object which stores pretty much all the other objects. I'm trying to pickle this object, but I get this error: pickle.PicklingError: Can't pickle : it's not found as builtin .module From what I can find on google, this is because somewhere I'm importing something outside of python init, or that a class attribute is referencing a module. So, I've got a two questions: Can

Remove or edit entry saved with Python pickle

♀尐吖头ヾ 提交于 2019-12-07 04:37:41
问题 I basically do sequences of dump and load, but at some point I want to delete one of the loaded entries. How can I do that? Is there a way to remove, or edit entries saved with Python pickle/cpickle? Edit: The data is saved with pickle in a binary file. 回答1: To delete a pickled object from a binary file you must rewrite the whole file. The pickle module doesn't deal with modifications at arbitrary portions of the stream, so there is no built-in way of doing what you want. Probably the

load a pickle file from a zipfile

瘦欲@ 提交于 2019-12-07 03:32:05
问题 For some reason I cannot get cPickle.load to work on the file-type object returned by ZipFile.open(). If I call read() on the file-type object returned by ZipFile.open() I can use cPickle.loads though. Example .... import zipfile import cPickle # the data we want to store some_data = {1: 'one', 2: 'two', 3: 'three'} # # create a zipped pickle file # zf = zipfile.ZipFile('zipped_pickle.zip', 'w', zipfile.ZIP_DEFLATED) zf.writestr('data.pkl', cPickle.dumps(some_data)) zf.close() # # cPickle

pandas.algos._return_false causes PicklingError with dill.dump_session on CentOS

跟風遠走 提交于 2019-12-07 03:28:42
问题 I have a code framework which involves dumping sessions with dill. This used to work just fine, until I started to use pandas. The following code raises a PicklingError on CentOS release 6.5: import pandas import dill dill.dump_session('x.dat') The problem seems to stem from pandas.algos. In fact, it's enough to run this to reproduce the error: import pandas.algos import dill dill.dump_session('x.dat') / dill.dumps(pandas.algos) The error is pickle.PicklingError: Can't pickle <cyfunction

python pickle - dumping a very huge list

北城以北 提交于 2019-12-07 03:22:27
I have two directories, each of which contains about 50,000 images, which are mostly 240x180 sizes. I want to pickle their pixel infos as training, validation, and test sets, but this apparently turns out to be very, very large, and eventually cause the computer to either free or run out of disk spaces. When the computer froze, the pkl file in the middle of being generated was 28GB. I'm not sure if this is supposed to be this large. Am I doing something wrong? Or is there a more efficient way to do this? from PIL import Image import pickle import os indir1 = 'Positive' indir2 = 'Negative'

cPickle:SystemError: error return without exception set

随声附和 提交于 2019-12-07 03:10:22
问题 While dumping large matrix (170000*20000) as follows cPickle.dump(train_set,gzip.open('train.pickle.gz','wb'), cPickle.HIGHEST_PROTOCOL) I get following error: SystemError: error return without exception set How would I deal in this case? 回答1: cPickle can't be used for storing very large objects ( see http://bugs.python.org/issue11564 ). You have several options: split the data into chunks and store it in multiple files numpy.save h5py <- my favorite because of its convenient numpy-like

Pandas Dataframe AttributeError: 'DataFrame' object has no attribute 'design_info'

心已入冬 提交于 2019-12-06 21:59:45
问题 I am trying to use the predict() function of the statsmodels.formula.api OLS implementation. When I pass a new data frame to the function to get predicted values for an out-of-sample dataset result.predict(newdf) returns the following error: 'DataFrame' object has no attribute 'design_info' . What does this mean and how do I fix it? The full traceback is: p = result.predict(newdf) File "C:\Python27\lib\site-packages\statsmodels\base\model.py", line 878, in predict exog = dmatrix(self.model