2

I have been reading about Python interpreters, especially CPython and PyPy, I know that there are 2 steps to run a Python code:

  1. Convert to Bytecode
  2. Interpre to MachineCode

My question is, if bytecode is generated by CPython, lets say Python version 2.7.0, will the bytecode run on PyPy for Python 2.7.0?

1
  • I wouldn't think so. Byte codes are part of the implementation, so I wouldn't expect them to be portable over implementations. Commented Oct 20, 2016 at 0:48

1 Answer 1

1

No. The byte code changes between versions, and is tagged with a magic number to make it clear which interpreters it will work with. And that's just within CPython, between CPython and PyPy they don't even have to agree on where you'd look for the magic number, let alone what it means. .pyc files are largely an optimization, not portable in the way the source files are; they're only distributable if they're distributed with the interpreter that understands them.

Basically, the Python language standards covers source syntax and libraries, not byte code formats

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.