Install & Compatibility
Where this runs
tested against v0.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.168s · 18.6MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.160s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
dill
✓ import dill
dill is imported directly as 'dill'
A basic example demonstrating how to serialize and deserialize an object using dill.
import dill
# Serialize an object
obj = {'key': 'value'}
with open('obj.pkl', 'wb') as f:
dill.dump(obj, f)
# Deserialize the object
with open('obj.pkl', 'rb') as f:
loaded_obj = dill.load(f)
print(loaded_obj)
Errors
Common errors & fixes
AttributeError: module 'dill._dill' has no attribute 'log'
This error typically occurs due to an incompatibility or version mismatch between the installed `dill` library and another dependent package (e.g., `datasets`, `nlp`) that expects a specific internal attribute of `dill` which has been removed or renamed in a newer version.
fixDowngrade `dill` to a version compatible with the dependent library. For example, `pip install dill==0.3.5.1` or `pip install dill<0.3.6` if the issue is with `log` or `PY3` (check the dependent library's requirements).
ModuleNotFoundError: No module named 'dill'
The `dill` library is not installed in the Python environment where the code is being executed, or there is a naming conflict where a local script is named `dill.py`.
fixInstall the `dill` package using pip: `pip install dill`. If a local script is named `dill.py`, rename it to avoid conflicting with the library import.
_pickle.PicklingError: Can't pickle <class '__main__.MyClass'>: it's not the same object as __main__.MyClass
While `dill` enhances Python's `pickle`, complex objects, especially dynamically created classes or objects defined directly in the `__main__` module, can still sometimes cause `PicklingError` if their exact context or definition isn't correctly preserved or recreated during deserialization, particularly across different environments or when `dill` is used with default `pickle`-like behavior for certain types.
fixEnsure you are explicitly importing and using `dill` for serialization and deserialization (e.g., `import dill; dill.dump(obj, file)`). For classes defined in `__main__` or when pickling modules, setting `dill.settings['recurse'] = True` before pickling can help `dill` trace and serialize global objects more comprehensively.
UnpicklingError: pickle data was truncated
This error indicates that the `.pkl` file being loaded is incomplete or corrupted, most often because the file writing process (e.g., from `dill.dump()` or `dill.dump_session()`) was interrupted or failed to write all data to disk.
fixEnsure that the `dill.dump()` or `dill.dump_session()` operation completes successfully, and that the file buffer is flushed (e.g., `f.flush(); os.fsync(f.fileno())` for file objects) if writing to disk. Verify there is sufficient disk space when creating the pickled file, and regenerate the file if it is corrupted.
TypeError: 'module' object is not callable
This error occurs when the `dill` module itself is mistakenly called as a function (e.g., `dill(...)`) instead of invoking its specific functions (like `dill.load()` or `dill.dumps()`). It can also rarely indicate an incorrect import of another module like `pprint` in older contexts.
fixCorrect the function call to use the appropriate `dill` method, such as `dill.load(file)` or `dill.dumps(obj)`. If the error context involves `pprint`, ensure it's imported correctly, e.g., `from pprint import pprint` if `pprint` is intended to be used as a function.
Upgrade
Version history
0.4.1latest on PyPI · released Jan 19, 2026
Audit
Dependencies
setuptoolsrequiredRequired for installation