'Python Unpickling When Some Modules are not Installed

Here's the situation.

  • Computer A
    • Pickle dumps objects of different data types (built-in and not), including scikit-learn objects
  • Computer B
    • Does not have scikit-learn installed and it doesn't have to be installed
    • Pickle loads -> ModuleNotFoundError: No module named 'sklearn'

Is there a way to ignore this error and still successfully load the pickle file by, for example, replacing objects that depend on modules not installed with None or skipping them? Of course I could simply not include sklearn objects in the pickle file, but I'm wondering if the code in Computer B can be robust against this situation.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source