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

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -