Calling Python 2 script from Python 3

前端 未结 7 2172
青春惊慌失措
青春惊慌失措 2020-12-01 02:00

I have two scripts, the main is in Python 3, and the second one is written in Python 2 (it also uses a Python 2 library).

There is one method in the Python 2 script

7条回答
  •  一个人的身影
    2020-12-01 02:29

    Maybe to late, but there is one more simple option for call python2.7 scripts:

    script = ["python2.7", "script.py", "arg1"]    
    process = subprocess.Popen(" ".join(script),
                                            shell=True,  
                                            env={"PYTHONPATH": "."})
    

提交回复
热议问题