Registry / serialization / cloudpickle

cloudpickle

JSON →
library3.1.2pypypi✓ verified 52d ago

Cloudpickle extends the standard functionality of the pickle module, allowing the serialization of Python objects that are not natively serializable. Current version is 3.1.2, released regularly with bug fixes and features.

serializationdata
pip install cloudpickle
Install & Compatibility
Where this runs
tested against v3.1.2 · 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
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.066s · 17.9MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.5s · import 0.059s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cloudpickle
import cloudpickle
Make sure to use this import statement since the older imports are no longer supported in this version.

A simple quickstart example demonstrating serialization and deserialization.

import cloudpickle import os model = {'name': 'example_model'} # Serialize serialized_model = cloudpickle.dumps(model) # Deserialize loaded_model = cloudpickle.loads(serialized_model) print(loaded_model)
Debug
Known issues
breakingDropped support for Python versions 3.6 and 3.7
fix
Upgrade to Python 3.8 or newer.
affects: <=3.0.0
gotchaEnsure objects being pickled are supported by cloudpickle or face serialization errors.
fix
Check the cloudpickle documentation for supported object types.
affects: all
gotchaPip generated warnings regarding running as the 'root' user or an available update. These are non-critical but indicate best practices.
fix
It is recommended to use a virtual environment for pip operations (https://pip.pypa.io/warnings/venv) and update pip to the latest version by running 'pip install --upgrade pip'.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cloudpickle'
The cloudpickle library is not installed in the Python environment or the environment where the code is being executed.
fix
Install the library using pip: `pip install cloudpickle`
TypeError: cannot pickle '_thread.RLock' object
You are attempting to serialize an object that contains an unpicklable '_thread.RLock' instance, which is not designed to be transferable across processes or machines.
fix
Restructure your code to avoid pickling objects that contain thread-specific primitives like RLock, or ensure that such objects are reinitialized in the target process rather than being serialized and deserialized. For multiprocessing, ensure locks are created within the child process or use `multiprocessing.Manager` to share objects that handle serialization appropriately.
TypeError: code() argument 13 must be str, not int
This error often occurs when attempting to serialize Python code (e.g., functions or classes) using cloudpickle across Python environments with different minor versions, specifically between Python 3.10 and 3.12, due to changes in the internal structure of Python's CodeType constructor.
fix
Ensure that the Python version used for pickling (serializing) an object is the exact same minor version as the Python version used for unpickling (deserializing) it.
AttributeError: Can't get attribute '_function_setstate' on <module 'cloudpickle.cloudpickle' from ...>
This error typically indicates an incompatibility between different versions of cloudpickle itself or between cloudpickle and a framework/SDK (like SageMaker SDK) that relies on it, often occurring when serialization happens in one environment and deserialization in another with mismatched versions.
fix
Ensure that the `cloudpickle` version and any dependent libraries (e.g., SageMaker SDK) are consistent across all environments (e.g., local and remote execution environments). Downgrading or pinning `cloudpickle` to a specific, compatible version (e.g., `pip install cloudpickle==2.2.1`) can resolve this.
Upgrade
Version history
3.1.2latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
92 hits · last 30 days
node
16
seranking-bot
4
ahrefsbot
2
Meta
1
Amazon
1
amazonbot
1
Resources