2

I have a pickle file which is written by Windows, but I want to read it in macOs.

my code:

    with open(file_path, 'rb') as file:
        data = pickle.load(file)

then I get:

data = pickle.load(file)
ModuleNotFoundError: No module named 'copy_reg\r'

I guess it is because \r\n in windows and \r in mac, but i have no idea to deal with it

yuhan
  • 59
  • 4
  • How did you write the file? Python usually uses universal newlines. Did you by any chance pickle an object whose class is defined in a file which you have written on windows? Does this import `copy_reg`? – MisterMiyagi Aug 12 '19 at 12:11
  • Possible duplicate of [Is pickle file of python cross-platform?](https://stackoverflow.com/questions/1849523/is-pickle-file-of-python-cross-platform) – aschultz Aug 12 '19 at 12:12
  • @aschultz but i do use 'rb' in this pickle file – yuhan Aug 12 '19 at 12:16
  • @yuhan Hmm. I think that would work for reading a file created in Linux, when you're running a Windows script,. Maybe try newline='\r\n' instead of 'rb'? – aschultz Aug 12 '19 at 12:19
  • Did you found a solution? – EgoPingvina Mar 27 '21 at 18:04

0 Answers0