0

I am trying to run python file on the VM. First, i wrote the code on windows and saved my data on variable using:

pickle.dump(x_train, open("images.data", "wb")) 

Then, when i'm trying to run the program on linux i'm using:

x_train = pickle.load(open("images.data", "rb"))

and I get the error:

File "/usr/lib/python2.7/pickle.py", line 1384, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 864, in load
    dispatch[key](self)
KeyError: 'v'

On windows it worked good, anyone knows what could be the problem?

Thanks.

edit: When I run the program via python 3.7.7 (the same as the windows version) I got:

    Traceback (most recent call last):
  File "dogpretrained.py", line 127, in <module>
    x_train = pickle.load(open("images.data", "rb")) 
_pickle.UnpicklingError: invalid load key, 'v'.
ita12345
  • 1
  • 1
  • What version of python did you use to pickle on your windows machine? `import sys;print(sys.version)` would tell you. – tdelaney Jul 28 '20 at 21:31
  • You are unpickling to python v 2.7 (which has been end-of-life'd). Try `pickle.dump(x_train, open("images.data", "wb"), protcol=2)` on the Windows side. – tdelaney Jul 28 '20 at 21:34
  • I'm using in windows python 3.7.7, and I tried protocol = 2, but same error – ita12345 Jul 28 '20 at 23:30
  • different Python versions used different code in `pickle` and there was always problem to use file from one version in other version. BTW: to unpickle you have to install the same modules on both systems. – furas Jul 28 '20 at 23:31
  • Can you install a python 3.7 on the linux side? Even if it uses 2.7 by default, it likely has some 3.x packages that can install too. Python 2.7 is end of life and moving ahead is a good goal regardless. – tdelaney Jul 29 '20 at 04:03
  • Can this data be saved in a different format that isn't python dependent? I don't know what's in x_train, but if it can be saved in, say, csv or other agnostic format and then write a bit of code to import in whatever x_train is. That would side step 2x to 3x incompatibilities. – tdelaney Jul 29 '20 at 04:05
  • I installed python 3.7 on the linux, but i can't run the program using the new version. I succeeded running the program via python 3.5 but I got another error(I edited the message with the error above). The x_train is a 4D numpy array of images, I can do some dirty work and change it to csv if there aren't any other solution. – ita12345 Jul 29 '20 at 16:59
  • You need to run the same Python version on both. You're not providing enough detail about why you couldn't run the correct Python version on Linux; that seems like a separate question anyway. – tripleee Jul 29 '20 at 17:25
  • Ok, I succeeded to run the program via python 3.7.7 (the same as the windows version), but still I get the error mentioned above. – ita12345 Jul 30 '20 at 09:54

0 Answers0