dill

How to install dill in IPython?

瘦欲@ 提交于 2019-12-06 08:58:59
问题 Right at the outset, I tried conda install dill , and conda was not able to find it on the internet. Then I downloaded both .tgz and .zip files in my default IPython directory from here: https://pypi.python.org/pypi/dill After which I tried the following commands: conda install dill-0.2b1.zip conda install "C:\<rest_of_the_complete_path>\dill-0.2b1.zip" and likewise for .tgz . All four attempts yielded the error: No packages found matching: What is it that I am doing wrong? I am trying to

Serializing an object in __main__ with pickle or dill

柔情痞子 提交于 2019-12-05 18:13:11
I have a pickling problem. I want to serialize a function in my main script, then load it and run it in another script. To demonstrate this, I've made 2 scripts: Attempt 1: The naive way: dill_pickle_script_1.py import pickle import time def my_func(a, b): time.sleep(0.1) # The purpose of this will become evident at the end return a+b if __name__ == '__main__': with open('testfile.pkl', 'wb') as f: pickle.dump(my_func, f) dill_pickle_script_2.py import pickle if __name__ == '__main__': with open('testfile.pkl') as f: func = pickle.load(f) assert func(1, 2)==3 Problem : when I run script 2, I

Unable to retrieve data after using dill or pickle

情到浓时终转凉″ 提交于 2019-12-04 05:47:21
问题 I dumped a Jupyter Notebook session using dill.dump_session(filename) , and at one point it told me that the disk storage was full. However, I made some space on the disk and tried again. Now, I am unable to load back the session using, dill.load_session(filename) . I get the following error: ~/.local/lib/python3.6/site-packages/dill/_dill.py in load_session(filename, main) 408 unpickler._main = main 409 unpickler._session = True --> 410 module = unpickler.load() 411 unpickler._session =

How to dill (pickle) to file?

删除回忆录丶 提交于 2019-12-01 04:16:15
The question may seem a little basic, but wasn't able to find anything that I understood in the internet. How do I store something that I pickled with dill? I have come this far for saving my construct (pandas DataFrame, which also contains custom classes): import dill dill_file = open("data/2017-02-10_21:43_resultstatsDF", "wb") dill_file.write(dill.dumps(resultstatsDF)) dill_file.close() and for reading dill_file = open("data/2017-02-10_21:43_resultstatsDF", "rb") resultstatsDF_out = dill.load(dill_file.read()) dill_file.close() but I when reading I get the error TypeError: file must have

How to dill (pickle) to file?

隐身守侯 提交于 2019-12-01 01:27:50
问题 The question may seem a little basic, but wasn't able to find anything that I understood in the internet. How do I store something that I pickled with dill? I have come this far for saving my construct (pandas DataFrame, which also contains custom classes): import dill dill_file = open("data/2017-02-10_21:43_resultstatsDF", "wb") dill_file.write(dill.dumps(resultstatsDF)) dill_file.close() and for reading dill_file = open("data/2017-02-10_21:43_resultstatsDF", "rb") resultstatsDF_out = dill

How can I recover a corrupted, partially pickled file?

人走茶凉 提交于 2019-11-30 09:54:13
问题 My program was killed while serializing data (a dict ) to disk with dill . I cannot open the partially-written file now. Is it possible to partially or fully recover the data? If so, how? Here's what I've tried: >>> dill.load(open(filename, 'rb')) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lib/python3.4/site-packages/dill/dill.py", line 288, in load obj = pik.load() EOFError: Ran out of input >>> The file is not empty: >>> os.stat(filename).st_size 31110059

Serialize a python function with dependencies

北慕城南 提交于 2019-11-30 09:37:35
I have tried multiple approaches to pickle a python function with dependencies, following many recommendations on StackOverflow, (such as dill, cloudpickle, etc.) but all seem to run into a fundamental issue that I cannot figure out. I have a main module that tries to pickle a function from an imported module, sends it over ssh to be unpickled and executed at a remote machine. So main has: import dill (for example) import modulea serial=dill.dumps( modulea.func ) send (serial) On the remote machine: import dill receive serial funcremote = dill.loads( serial ) funcremote() If the functions

What are the pitfalls of using Dill to serialise scikit-learn/statsmodels models?

谁说胖子不能爱 提交于 2019-11-30 00:10:58
I need to serialise scikit-learn/statsmodels models such that all the dependencies (code + data) are packaged in an artefact and this artefact can be used to initialise the model and make predictions. Using the pickle module is not an option because this will only take care of the data dependency (the code will not be packaged). So, I have been conducting experiments with Dill . To make my question more precise, the following is an example where I build a model and persist it. from sklearn import datasets from sklearn import svm from sklearn.preprocessing import Normalizer import dill digits =

How can I recover a corrupted, partially pickled file?

倖福魔咒の 提交于 2019-11-29 17:08:58
My program was killed while serializing data (a dict ) to disk with dill . I cannot open the partially-written file now. Is it possible to partially or fully recover the data? If so, how? Here's what I've tried: >>> dill.load(open(filename, 'rb')) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lib/python3.4/site-packages/dill/dill.py", line 288, in load obj = pik.load() EOFError: Ran out of input >>> The file is not empty: >>> os.stat(filename).st_size 31110059 Note: all data in the dictionary was comprised of python built-in types. The pure-Python version of

`pickle`: yet another `ImportError: No module named my_module`

被刻印的时光 ゝ 提交于 2019-11-28 10:22:34
问题 I have a class MyClass defined in my_module . MyClass has a method pickle_myself which pickles the instance of the class in question: def pickle_myself(self, pkl_file_path): with open(pkl_file_path, 'w+') as f: pkl.dump(self, f, protocol=2) I have made sure that my_module is in PYTHONPATH . In the interpreter, executing __import__('my_module') works fine: >>> __import__('my_module') <module 'my_module' from 'A:\my_stuff\my_module.pyc'> However, when eventually loading the file, I get: File "A