c++ - Run python scripts (different python verions) with one C program -


i want run few python scripts in threads small c/++ program, need different python versions run these scripts, because package mysqldb isn't working in python3 , packages aren't available in python2.

#include <stdio.h> #include <python2.7/python.h> #include <python3/python.h>  void main(int argc, char *argv[]) {     file* file;      py_setprogramname(argv[0]);     py_initialize();     pysys_setargv(argc, argv);     file = fopen("myscript.py","r");     pyrun_simplefile(file, "myscript.py");     py_finalize();      return; } 

or via

system ("python2.7 myscript1.py arg1 arg2"); system ("python3 myscript2.py arg1 arg2"); 

do have ideas or way solve problem?

you can use system() call execute python scripts, there no need of specifying version of python executable on command line.

you can use shebang.

use #!/usr/bin/python3 first line scripts want run python3 , #!/usr/bin/python2 in scripts want run python2.

if working on windows please have @ python launcher


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -