
On 27/08/21 11:27 pm, Evan Greenup via Python-ideas wrote:
If it contains function it will persist all its attribute, and code object.
For example, if user pickle recursively dump a numpy ndarray into a pickle file, when user pickle load this file from a system which doesn't install numpy, its method should all works properly like transpose, reshape ...
By design, pickle doesn't save code objects, but even if it did, most of numpy is not written in Python, so it wouldn't help in that case.
You're effectively asking for pickling of binary machine code, which would be very difficult to do. Even if you were successful, the resulting pickle would be very closely tied to both a platform and a particular version of Python and all its libraries.
As the example of numpy ndarray, when doing recursively dump, large part of numpy library's content will be persist except those really lose or none coupled part.
Selecting individual machine code routines out of numpy and saving and restoring them individually is probably not feasible, so you would have to just dump the whole lot as one binary blob. At that point it would be a lot easier and more reliable just to tell the user to install numpy.