【问题标题】:Embedding Python 3.3嵌入 Python 3.3
【发布时间】:2013-02-21 16:26:25
【问题描述】:

我尝试嵌入 Python 3.3,如 here 所述。

我使用的是具有 Python 2.7 的 MacOS 10.8,因此我从 python.org 下载了 3.3 版的二进制分发版。从中我得到了所有标题和“Python”,我将它们重命名为“python33”,因此它不会与已安装的“Python”库发生冲突。我把所有东西都放到一个文件夹里:

embed.c /include python33

“文件python33”说:

python33 (for architecture i386):   Mach-O dynamically linked shared library i386
python33 (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64

而 embed.c 是:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString("print 'test'\n");
  Py_Finalize();
  return 0;
}

但是当我执行“gcc embed.c -I./include -L.-lpython33”时,它会中断:

ld: library not found for -lpython33

请问有谁知道怎么编译?

【问题讨论】:

    标签: python c python-3.x linker embedding


    【解决方案1】:

    运行python3.3-config --cflags,您将获得系统所需的 cflags。对于 ldflags,命令为python3.3-config --ldflags

    【讨论】:

    • ./python3.3-config --> -bash: ./python3.3-config: /Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3m: 错误的解释器: 没有这样的文件或目录
    • 在我的系统上(OS X 10.8.2 和来自官方安装程序的 python 3.3)它的工作就像一个魅力。我的输出是 -I/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -I/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -fno-strict-aliasing - fno-common -dynamic -DNDEBUG -g -O3 -arch i386 -arch x86_64 -L/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/config-3.3m -ldl -framework CoreFoundation -lpython3。 3m
    • 我没有安装 Python 3.3 - 我只是下载了它并提取了主库。当我执行gcc embed.c -I./include -ldl -framework CoreFoundation -L. -lpython33 时,它仍然显示“ld: library not found for -lpython33”
    • 显然。在尝试使用它之前安装它是个好主意。
    • 我只想嵌入它并将所需的库与可执行文件捆绑在一起。我是否必须安装 Python 3.3?我认为,由于可以运行一个程序,而无需实际安装其所有库,就可以运行它的所有依赖项,因此应该可以从预编译的 Python 中复制所需的库并将它们与可执行文件捆绑在一起?
    【解决方案2】:

    首先,该库必须以“libxxx.so”的形式命名,然后链接器将使用“-L”找到它。 -lxxx'。

    即便如此,生成的可执行文件也无法正常工作,因为人们不仅要复制/创建库,还要复制/创建整个框架。

    更多:http://lists.apple.com/archives/cocoa-dev/2013/Feb/msg00522.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-06
      • 2013-03-27
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多