0

I would like to determine which version of python a pyc file was compiled with. I do not have access to the original py file. I already attempted the following based on the accepted answer to a similar question:

>>> f = open('pyc_file.pyc')
>>> magic = f.read(4)

However, in my case I get an error:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 433: character maps to undefined

Why does this error occur? How can I determine the correct version that the pyc file was compiled as?

user32882
  • 4,174
  • 4
  • 28
  • 56
  • Open the file in binary mode. `f = open('pyc.file.pyc', 'rb')`. You have used the form of `open` appropriate for text files. Python is trying to interpret the binary stuff in a .pyc file as text and is failing. – Frank Yellin Jan 09 '22 at 19:43

0 Answers0