pythonwindowspython-3.xcommand-linemultiple-versions

Python script to run command line which starts python script with specific python version


I need some help. Is there a possibility to let python start the command line in windows and let the command line execute a script in another python version on my pc?

Expample: I have two versions of python on my pc. One is within Anaconda and the other one is pure Python. Now I have some scripts I want to be executed in specific order. My problem is, that the Google Analytics API doesn't work with Anaconda and some other packages (like Simpy) doesn't work with pure Python. So I need to work with two different versions of python for one project.

Now I want to write a litte python file, which opens the command line and executes the scrips in specific order on my different Python-versions.

I know how to run a python file on the command line. It's via

C:\path_to_python\python.exe C:\path_to_file\file.py

But how can I make a python script executing that line above in the command line?

Hope someone can help me.

Thanks.


Solution

  • import os
    os.system("C:\path_to_python\python.exe C:\path_to_file\file.py")
    

    os.system() returns the command's exit value so if you need some output from the script this won't work.