{"id":387,"library":"cloudpickle","title":"Cloudpickle","description":"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.","status":"active","version":"3.1.2","language":"python","source_language":"en","source_url":"https://github.com/cloudpipe/cloudpickle","tags":["serialization","pickle","cloudpickle","python"],"install":[{"cmd":"pip install cloudpickle","lang":"bash","label":"Install Cloudpickle"}],"dependencies":[],"imports":[{"note":"Make sure to use this import statement since the older imports are no longer supported in this version.","symbol":"cloudpickle","correct":"import cloudpickle"}],"quickstart":{"code":"import cloudpickle\nimport os\n\nmodel = {'name': 'example_model'}\n\n# Serialize\nserialized_model = cloudpickle.dumps(model)\n\n# Deserialize\nloaded_model = cloudpickle.loads(serialized_model)\nprint(loaded_model)","lang":"python","description":"A simple quickstart example demonstrating serialization and deserialization."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer.","message":"Dropped support for Python versions 3.6 and 3.7","severity":"breaking","affected_versions":"<=3.0.0"},{"fix":"Check the cloudpickle documentation for supported object types.","message":"Ensure objects being pickled are supported by cloudpickle or face serialization errors.","severity":"gotcha","affected_versions":"all"},{"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'.","message":"Pip generated warnings regarding running as the 'root' user or an available update. These are non-critical but indicate best practices.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:27:46.050Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install cloudpickle`","cause":"The cloudpickle library is not installed in the Python environment or the environment where the code is being executed.","error":"ModuleNotFoundError: No module named 'cloudpickle'"},{"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.","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.","error":"TypeError: cannot pickle '_thread.RLock' object"},{"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.","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.","error":"TypeError: code() argument 13 must be str, not int"},{"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.","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.","error":"AttributeError: Can't get attribute '_function_setstate' on <module 'cloudpickle.cloudpickle' from ...>"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":2.4,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":2.4,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":2.6,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":2.6,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.6,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.6,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.8,"disk_size":"11.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.6,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":2.3,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":2.3,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}