Cloudpickle
raw JSON → 3.1.2 verified Tue May 12 auth: no python install: verified quickstart: verified
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.
pip install cloudpickle Common errors
error ModuleNotFoundError: No module named 'cloudpickle' ↓
cause 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 error TypeError: cannot pickle '_thread.RLock' object ↓
cause 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. error TypeError: code() argument 13 must be str, not int ↓
cause 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.
error AttributeError: Can't get attribute '_function_setstate' on <module 'cloudpickle.cloudpickle' from ...> ↓
cause 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. Warnings
breaking Dropped support for Python versions 3.6 and 3.7 ↓
fix Upgrade to Python 3.8 or newer.
gotcha Ensure objects being pickled are supported by cloudpickle or face serialization errors. ↓
fix Check the cloudpickle documentation for supported object types.
gotcha Pip 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'.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.05s 17.9M
3.10 slim (glibc) - - 0.03s 18M
3.11 alpine (musl) - - 0.10s 19.7M
3.11 slim (glibc) - - 0.08s 20M
3.12 alpine (musl) - - 0.07s 11.6M
3.12 slim (glibc) - - 0.07s 12M
3.13 alpine (musl) - - 0.07s 11.3M
3.13 slim (glibc) - - 0.07s 12M
3.9 alpine (musl) - - 0.04s 17.4M
3.9 slim (glibc) - - 0.04s 18M
Imports
- cloudpickle
import cloudpickle
Quickstart verified last tested: 2026-04-23
import cloudpickle
import os
model = {'name': 'example_model'}
# Serialize
serialized_model = cloudpickle.dumps(model)
# Deserialize
loaded_model = cloudpickle.loads(serialized_model)
print(loaded_model)