Python Forum
How to run together python3.10 and python3.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run together python3.10 and python3.7
#1
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?
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 string slicing Luchano55 4 534 Feb-17-2024, 09:40 AM
Last Post: Pedroski55
  Kivy App - Python3 script to Android app (opencv) jttolleson 7 3,322 Oct-19-2023, 01:11 PM
Last Post: MasCain
Sad Migrating of python2 script to python3 zuri 7 870 Oct-05-2023, 02:40 PM
Last Post: snippsat
  Migration of Python2 and Python3 using Modernize and Future Rakshan 5 2,455 Oct-05-2023, 08:55 AM
Last Post: zuri
  How can prepare the modules when compiling python3.11? luofeiyu 1 523 Sep-28-2023, 03:50 PM
Last Post: deanhystad
  Understanding and debugging memory error crashes with python3.10.10 Arkaik 5 1,977 Apr-18-2023, 03:22 AM
Last Post: Larz60+
  How should I run pip-date in python3? newbieAuggie2019 5 1,775 Mar-31-2023, 03:21 PM
Last Post: snippsat
  hypothesis 6.46.2 requires python3.7 or later Anldra12 6 1,562 Jun-22-2022, 11:05 AM
Last Post: Anldra12
  Python3 hashlib ogautier 1 1,495 Mar-28-2022, 04:42 AM
Last Post: snippsat
  Python3 url parse ogautier 5 2,523 Mar-04-2022, 06:56 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020