How To Run Code Using Both 3.2 And 2.7 Python Interpreter In Same Project?
I have two Python classes written in two different files. One is written in Python 2.7 and the other written in Python 3.2. One class is used inside the other. Is it possible to r
Solution 1:
I don't believe it is possible for them to be running in the same process, that is you will have to choose one or the other. Python3 and Python2 bytecode are not compatible with each other, which you can confirm by attempting to run Python2 bytecode in Python3:
% cat > test.py
a = 1
% python2.6 -m compileall .% python2.6 test.pyc% python3.1 test.pyc
RuntimeError: Bad magic number in .pyc file
Try something more complicated to be sure. Compile test.py
using Python2 and then remove the .py
file to make sure it isn't recompiled by Python3. Then, attempt to import the .pyc
bytecode into a Python3 interpreter.
% python2.6 -m compileall .% rm test.py% cat > test2.py
import test
print(test.a)
% python2.6 test2.py
1
% python3.1 test2.py
Traceback (most recent call last):
File "test2.py", line 1, in <module>
import test
ImportError: Bad magic number in test.pyc
Post a Comment for "How To Run Code Using Both 3.2 And 2.7 Python Interpreter In Same Project?"