diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index 17a1f9529..d6c140871 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -385,7 +385,7 @@ def _save_subimports(self, code, top_level_dependencies): """ # check if any known dependency is an imported package for x in top_level_dependencies: - if isinstance(x, types.ModuleType) and x.__package__: + if isinstance(x, types.ModuleType) and hasattr(x, '__package__') and x.__package__: # check if the package has any currently loaded sub-imports prefix = x.__name__ + '.' for name, module in sys.modules.items():