Cole Howard
Cole Howard

Reputation: 343

Python Pickle File from Linux Incompatible with Mac?

I am trying to pickle the state of a Python (Python3.5) instance with the code:

g = open(file_name, 'wb')
pickle.dump(network, g)
g.close()

When I run this on my mac locally, the pickle file looks like ...

8003 6366 696e 6e65 6761 6e2e 6e65 7477
6f72 6b0a 4e65 7477 6f72 6b0a 7100 2981
7101 7d71 0228 580c 0000 006e 6575 726f
...

And when I run it in a docker container ...

S'<'
p18
NNNI-1
I-1
I0
tp19
bI00
...

Is this a linux/mac conflict or is something else going on?

Upvotes: 2

Views: 1137

Answers (1)

Jashandeep Sohi
Jashandeep Sohi

Reputation: 5173

Try explicitly setting the protocol version, to make sure both machines are using the same version:

pickle.dump(network, g, protocol=4)

Upvotes: 2

Related Questions