在哪里放置.pys以嵌入Python repo?

2024-03-28 19:22:04 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在C++中用PybDun11嵌入这个^ a1}?你知道吗

我的Visual Studio项目设置:

Python头文件和库文件(lib)在“properties>;VC++目录”中说明 /Python安装文件夹中的Lib放在.vcxproj文件夹中 .py位于包含.exe的发行版文件夹中

示例

#include <iostream>
#include <pybind11/embed.h>

namespace py = pybind11;

int main()
{
    py::scoped_interpreter guard{}; // start the interpreter and keep it alive

    py::print("Hello, World!"); // use the Python API

    int i;
    std::cin >> i;
    return 0;
}

这个代码运行到目前为止,所以我想到目前为止,我做的一切都是对的。你知道吗

嵌入

我已经测试了嵌入,这也有效。你知道吗

计算py

def add(a, b):
    return a+b

我放置文件的位置

我把计算py在release文件夹中运行.exe和以下程序:

#include 
#include <pybind11/embed.h>

namespace py = pybind11;

int main()
{
    py::scoped_interpreter guard{}; // start the interpreter and keep it alive

    py::module calc = py::module::import("calc");
    py::object result = calc.attr("add")(1, 2);
    int n = result.cast<int>();

    std::cout << "The result: " << n << std::endl;

    int i;
    std::cin >> i;
    return 0;
}

我的问题

我想嵌入这个应用:https://github.com/LevPasha/Instagram-API-python 我需要怎么做才能从这个文件中调用构造函数:https://github.com/LevPasha/Instagram-API-python/blob/master/InstagramAPI/InstagramAPI.py

我已经用pip安装了存储库,我知道我用pip show InstagramAPI找到了它的安装文件夹。我是否需要再次将这些文件放在VisualStudio项目的发行版文件夹中?你知道吗

这些是Instagram Api的依赖项:

需要:请求,请求工具带,moviepy

我需要考虑他们吗?你知道吗

我已经绝望了,因为我已经试了好几天了。请帮帮我。你知道吗


Tags: 文件thepy文件夹apireturnincludecalc