python-embedding

Limiting execution time of embedded Python

空扰寡人 提交于 2019-12-05 15:38:15
问题 If I embed the Python interpreter in a C or C++ program, as in this example, is there any way to limit how long the interpreter runs for? Is there anything to stop the Python code from entering an infinite loop and thus preventing PyObject_CallObject (or equivalent) from ever returning? Similarly, if the Python code creates a new thread, is there anything to stop this thread from entering an infinite loop and running forever? 回答1: As you can see in the docs, PyObject_CallObject has no

Embedding Python in C: Error in linking - undefined reference to PyString_AsString

扶醉桌前 提交于 2019-12-05 10:48:59
I am trying to embed a python program inside a C program. My OS is Ubuntu 14.04 I try to embed python 2.7 and python 3.4 interpreter in the same C code base (as separate applications). The compilation and linking works when embedding python 2.7 but not for the python 3.4. It fails during the linker stage. Here is my C code (just an example not real code) simple.c #include <stdio.h> #include <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pFunc, *pValue; char module[] = "get_version"; char func[] = "get_version"; char module_path[] = "."; Py_Initialize(); PyObject *sys

Embedding Python in Qt 5

邮差的信 提交于 2019-12-05 05:35:02
I would like to embed Python interpreter in to a Qt 5 application. I have a working application in Qt 5 but when I put #include <Python.h> at the top (below Qt headers) the compilation breaks with ../sample/python3.3m/object.h:432:23: error: expected member name or ';' after declaration specifiers PyType_Slot *slots; /* terminated by slot==0. */ ~~~~~~~~~~~ ^ When I put Python header above the Qt headers it breaks with In file included from ../Qt5.0.1/5.0.1/clang_64/include/QtGui/QtGui:59: ../Qt5.0.1/5.0.1/clang_64/include/QtGui/qpagedpaintdevice.h:63:57: error: expected '}' A0, A1, A2, A3, A5

Minimal Python build for my application's scripting needs?

拜拜、爱过 提交于 2019-12-05 04:05:29
问题 what are your advices on building a very minimalistic version of Python(2.x) for my application's scripting needs. My main motive here is to keep the foot print (both memory and disk wise) as low as possible so that my native application won't suffer from any major performance hit. Even the Python DLL size is in consideration because of the possibility of increasing boot up time of my application. Can we go as low as Lua or other lightweight solutions? 回答1: Have you tried Tiny Python? 回答2:

Does the Python 3 interpreter leak memory when embedded?

泄露秘密 提交于 2019-12-05 01:24:09
问题 This bug report states that the Python interpreter, as of June 2007, will not clean up all allocated memory after calling Py_Finalize in a C/C++ application with an embedded Python interpreter. It was recommended to call Py_Finalize once at application termination. This bug report states that as of version 3.3 and March 2011 the interpreter still leaks memory. Does anyone know the current state of this issue? I am concerned because I have an application in which the interpreter is called

“AttributeError: 'module' object has no attribute 'argv'” when using Python.h

给你一囗甜甜゛ 提交于 2019-12-05 01:13:00
When messing around with Python.h I got this error: AttributeError: 'module' object has no attribute 'argv' C++ code: #include "stdafx.h" #include "C:/Python27/include/Python.h" #include <iostream> using namespace std; int main() { Py_Initialize(); PyRun_SimpleString("import sys\nprint sys.argv[0]"); } Which in Python is: import sys print sys.argv[0] What am I missing? Conceptually, sys.argv should contain the arguments that Python was called with (and what it was called under). What should it have if it were called like this, though? You can load the calling program's argv into sys , if you

PyObject_CallMethod with keyword arguments

雨燕双飞 提交于 2019-12-04 22:28:11
问题 I'm trying to embed a Python (2.7) library in my C application and I'm using the Python/C API to call Python code from C. I need to call a Python method that takes keyword arguments. Semantically, I'm trying to achieve the equivalent of the following line in Python: myobject.dosomething('blahdy blah', somearg=True) By reading the documentation, I have managed to get as far as the following, but this doesn't pass in the keyword arguments: PyObject_CallMethod(myobject, "dosomething", "s",

Embedding a matplotlib chart into Qt/C++ application

♀尐吖头ヾ 提交于 2019-12-04 18:44:03
问题 I am developing an math-oriented GUI application in Qt/C++ and would like to embed a Python scripting, including NumPy and Matplotlib. Using Python C API, I finally managed to run a script, retrieve the values from the Python variables, including NumPy arrays etc. But I failed at drawing Matplotlib charts into my Qt/C++ application. It is better to say, I have managed to save the chart's RGBA buffer to a variable using Python script, then get the value of the variable as a PyObject of buffer

Limiting execution time of embedded Python

夙愿已清 提交于 2019-12-04 01:21:35
If I embed the Python interpreter in a C or C++ program, as in this example , is there any way to limit how long the interpreter runs for? Is there anything to stop the Python code from entering an infinite loop and thus preventing PyObject_CallObject (or equivalent) from ever returning? Similarly, if the Python code creates a new thread, is there anything to stop this thread from entering an infinite loop and running forever? Peter Brittain As you can see in the docs , PyObject_CallObject has no mechanism for limiting how long the function runs. There is also no Python C API function that I

Minimal Python build for my application's scripting needs?

我怕爱的太早我们不能终老 提交于 2019-12-03 21:17:14
what are your advices on building a very minimalistic version of Python(2.x) for my application's scripting needs. My main motive here is to keep the foot print (both memory and disk wise) as low as possible so that my native application won't suffer from any major performance hit. Even the Python DLL size is in consideration because of the possibility of increasing boot up time of my application. Can we go as low as Lua or other lightweight solutions? Have you tried Tiny Python ? You can use only the dll 来源: https://stackoverflow.com/questions/356452/minimal-python-build-for-my-applications