I am designing a GUI using the wxPython toolkit, which means it's being written in python2. However, I want to use python3 for the actual application code. How would I go about calling my python3 code from the GUI?
To use the Python 3 processor for Python code within a program block, use BEGIN PROGRAM PYTHON3-END PROGRAM . By default, Python scripts that are run from the SCRIPT command are run with the Python 2 processor. To run a script that uses the Python 3 processor, use PYTHONVERSION=3 on the SCRIPT command.
The latest stable version is Python 3.9 which was released in 2020. The nature of python 3 is that the changes made in python 3 make it incompatible with python 2. So it is backward incompatible and code written in python 3 will not work on python 2 without modifications.
Python version 3 is not backwardly compatible with Python 2. Many recent developers are creating libraries which you can only use with Python 3. Many older libraries created for Python 2 is not forward-compatible.
Basically, developers deliberately made python 3 not backwards compatible, for two main reasons: First of all, they wanted to change some things integral to python 2, and while the differences seemed small, the improvements that they had made would not have combined well with the existing structure.
Talk over a pipe or socket
Enable such python 3 features as you can from __future__
or use a library like six
to write code which is compatible with both.
Don't do this.
Finally, are you sure you can't use wxPython in Python 3? There's nothing in the online docs saying you can't.
You can run the application code as a shell script.
from subprocess import call
exit_code = call("python3 my_python_3_code.py", shell=True)
You can also pass in terminal arguments as usual.
arg1 = "foo"
arg2 = "bar"
exit_code = call("python3 my_python_3_code.py " + arg1 + " " + arg2, shell=True)
If you want to collect more information back from the application you can instead capture stdout as describe here: Capture subprocess output
If you want to fluidly communicate in both directions a pipe or socket is probably best.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With