python - 从 C++ 运行 python 脚本

标签 python c++

我想从 c 运行一个 python 脚本。我试过它编译成功但它给出错误“python 不被识别为内部或外部命令、可运行的程序或批处理文件”。

 #include <iostream>
 using namespace std;
 // main() is where program execution begins.

 int main()
 {
    std::string filename = "hi.py";
    std::string command = "python ";
    command += filename;


    FILE* in = popen(command.c_str(), "r");
    pclose(in);
    return 0;
 }

最佳答案

您想使用 python 可执行文件的完整路径,例如:

std::string command = "/usr/bin/python ";

关于python - 从 C++ 运行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33526534/

相关文章:

python - 使来自全局站点包的一些模块在 virtualenv 中可用

python - 配置 AppEngine 上的空闲实例数

python - 应用 SciPy.ndimage 中的 Sobel 滤波器

python - 为什么 PyObjC 文档如此糟糕?

python - Tornado set_secure_cookie unicode 错误

c++ - 为什么我必须链接到 opengl32.lib

c++ - 如何移动计算出的圆的位置?

c++ - map<T,T>::iterator 作为参数类型

c++ - 我对 SDL 的简单介绍程序没有构建。为什么我会收到这些链接器错误?

c++ - 初始化 LPCTSTR/LPCWSTR