Questions tagged [python-embedding]

Questions regarding embedding Python interpreter in other applications, such that it may serve as a scripting language.

When embedding Python, the interface code does:

  • Convert data values from C to Python,

  • Perform a function call to a Python interface routine using the converted values, and

  • Convert the data values from the call from Python to C.

Reference

309 questions
10
votes
1 answer

Embedding IronPython in a WinForms app and interrupting execution

BACKGROUND I've successfully embedded IronPython in my WinForm apps using techniques like the one described here: http://blog.peterlesliemorris.com/archive/2010/05/19/embedding-ironpython-into-a-c-application.aspx In the context of the embedding,…
namenlos
  • 5,111
  • 10
  • 38
  • 38
10
votes
3 answers

Embedding a matplotlib animation into a tkinter frame

For a project I am working on a simple harmonic motion simulator (How a mass oscillates over time). I have got the data produced correctly and already have a graph produced within a tkinter frame work. At the moment it only shows a static graph…
user3208454
  • 131
  • 1
  • 1
  • 6
10
votes
4 answers

Why does PyImport_Import fail to load a module from the current directory?

I'm trying to run the embedding example and I can't load a module from the current working directory unless I explicitly add it to sys.path then it works: PyRun_SimpleString("import sys"); PyRun_SimpleString("sys.path.append(\".\")"); Shouldn't…
iabdalkader
  • 17,009
  • 4
  • 47
  • 74
10
votes
2 answers

(Python C API) PyRun_StringFlags missing builtin functions?

I am trying to embed some python in my pet project. I have reduced my problem to the following code: #include #include "iostream" int main(int argc, char *argv[]) { Py_Initialize(); PyObject *globals = Py_BuildValue("{}"); …
Simon
  • 961
  • 2
  • 9
  • 14
9
votes
2 answers

PyObject_CallMethod with keyword arguments

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…
Tamas Czinege
  • 118,853
  • 40
  • 150
  • 176
9
votes
6 answers

Python interpreter as a c++ class

I am working on embedding python in to c++. In some peculiar case I require two separate instances of the interpreter in same thread. Can I wrap Python interpreter in to a c++ class and get services from two or more class instances?
Amol Gawai
  • 3,220
  • 4
  • 23
  • 25
8
votes
1 answer

Embedded Python 2.7.2 Importing a module from a user-defined directory

I'm embedding Python into a C/C++ application that will have a defined API. The application needs to instantiate classes defined in a script, which are structured roughly like this: class userscript1: def __init__(self): ##do something…
Fritz
  • 274
  • 3
  • 16
8
votes
1 answer

Do PyImport_ImportModule and import statement load into different namespace?

Here is canonical example of a program extending embedded Python 3.x in C/C++: #include //// Definition of 'emb' Python module //////////////////// static PyObject* emb_foo(PyObject *self, PyObject *args) { char const* n = "I am…
mloskot
  • 37,086
  • 11
  • 109
  • 136
8
votes
3 answers

Which standard library modules are required to run the Python 3.5 interpreter?

Here's a CPython program that tries to initialize the interpreter with an empty sys.path: #include int main(int argc, char** argv) { wchar_t* program = NULL; wchar_t* sys_path = NULL; Py_NoSiteFlag = 1; program =…
bzrr
  • 1,490
  • 3
  • 20
  • 39
8
votes
2 answers

Is it possible to embed python without the standard library?

Is it possible to embed python without the standard library? I'm working with a cmake build for python 2.7.6 and I've got a basic embedded script running, like so: #include #include int main(int argc, char *argv[]) { /*…
Doug
  • 32,844
  • 38
  • 166
  • 222
8
votes
2 answers

Embedding Python in Qt 5

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 at the top (below Qt headers) the compilation breaks with ../sample/python3.3m/object.h:432:23: error:…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
7
votes
1 answer

embedding python

Im trying to call python functions from C code, and i followed a sample from here I also have the correct include file directries, library directries, and linked the python32.lib (im using python 32) however the error was that python/C APIs such as…
PeterG
  • 519
  • 2
  • 7
  • 15
7
votes
2 answers

Embedding Python into C - importing modules

I am having problems using the Embedded Python for C as per the Documentation - Whenever I try using imported modules I get an : Unhandled exception at 0x1e089e85 in PythonIncl.exe: 0xC0000005: Access violation reading location 0x00000004. The…
Shorkaa
  • 123
  • 3
  • 5
7
votes
1 answer

Embedded python code in c++ - error when importing python libraries

I am trying to use Python 3.5 interpreter embedded in a C++ program to receive an image from C++, and use it as an input for my trained tensorflow model. First, I convert my image to numpy array and then send it to python. This is my simplified code…
Matin H
  • 870
  • 8
  • 16
7
votes
2 answers

Embed Python 3.5 with tkinter support on Windows

My project structure looks like this: emb | CMakeLists.txt | main.c | python35.lib | stdlib.zip | _tkinter.pyd | +---include | | | | abstract.h | | accu.h | | asdl.h ... | | warnings.h | | …
bzrr
  • 1,490
  • 3
  • 20
  • 39
1
2
3
20 21