Hi everyone. I have a code which is written with python3.7
Because of python3.7 doesnt have switch-case I wrote another code script with python3.10
I need to run these two code snippets together. I dont know how to do it due to version difference. I cannot change the code with python3.7 because it has pysnmp and it runs only 3.7 version.
Can anybody help me with this issue?
I installed
pysnmp on Python 3.11 and the command line tool seems to work. No import error.
If you want to run from Python another Python with a different version, it requires a new process.
You could use
subprocess.run
to run the script with Python 3.11 or another version.
I use for this
pyenv.
Example: p39.py
import sys
import subprocess
from pathlib import Path
PYENV = Path.home() / ".pyenv/versions"
def run_with(script, version, *args):
exe = PYENV / version / "bin/python"
subprocess.run([exe, script, *args])
print("Hello from", sys.version)
run_with("p311.py", "3.11.0")
p311.py
import sys
print("Hello from", sys.version)
Output:
Output:
[andre@andre-Fujitsu-i5 ~]$ python p39.py
Hello from 3.9.15 (main, Oct 26 2022, 09:59:12)
[GCC 12.2.0]
Hello from 3.11.0 (main, Oct 25 2022, 10:22:43) [GCC 12.2.0]
[andre@andre-Fujitsu-i5 ~]$
The better approach is to use pysnmp with the latest installed python version.
I don't know why you have problems to install it.
You need at least two processes, one (A) that runs Python 3.7 and pysnmp and the other one (B) that runs Python 3.10. Then the two processes need to communicate.
You could for example dress up process A as a remote procedure call server, by using a module such as rpyc, and process B could invoke functions in process A through remote calls. These functions in turn would call pysnmp functions.