1
vote
2answers
616 views

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 ...
11
votes
6answers
6k views

Calling a python method from C/C++, and extracting its return value

I'd like to call a custom function that is defined in a python module from C. I have some preliminary code to do that, but it just prints the output to stdout. mytest.py import math def myabs(x): ...
7
votes
5answers
3k views

Is it possible to modify PYTHONPATH at runtime?

I have a C++ application dynamically linked to the Python interpreter. I want to be able to import python modules from a particular directory. I want to modify the PYTHONPATH for my process so that ...
1
vote
0answers
63 views

Embedding Python: How to use custom type inside Python script?

I try to run some Python scripts from inside the C++ code. I reach the point, in which I need to use my custom type. I found article in Python doc about creating custom types and nice SOQ, explaining ...
2
votes
1answer
50 views

Nested modules (packages) with python c api?

How can I create nested modules (packages?) with the python c api? I would like the client code (python) to be able do something like this: import MainModuleName import MainModuleName.SubModuleName ...
1
vote
1answer
96 views

Dynamic arg types for a python function when embedding

I am adding to Exim an embedded python interpreter. I have copied the embedded perl interface and expect python to work the same as the long-since-coded embedded perl interpreter. The goal is to ...
0
votes
1answer
50 views

Embedding Python 3.3: How do I access _PyParser_Grammar?

I am attempting to emulate the Python/C API's PyRun_InteractiveLoop() function, but from a different input system used by my employer. The Python FAQ ...
2
votes
1answer
1k views

Python C API doesn't load module

I'm trying to load a python module that contains a math and numpy import in C, using the C API. I can load and run the module but, if I import the math module it doesn't work. I'm using Arch Linux, ...
3
votes
2answers
3k views

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: ...
0
votes
1answer
162 views

Embedding Python 3.3 in a C++ program while only able to read one line at a time from input

I am currently working on adding embedded Python support (and yes, extending is not an option) to a large program as part of my summer internship. Ideally, I can keep the Python support within a ...
1
vote
2answers
742 views

embedding python error on initialization

when im running C code to call python functions, there's error on Py_Initialize() The error is ImportError: No module named site. Ive tried to put Py_SetProgramName(argv[0]) but it doesnt work. The ...
6
votes
2answers
4k views

How To catch python stdout in c++ code

I have a program which during it's run sometimes needs to call python in order to preform some tasks. I need a function that calls python and catches pythons stdout and puts it in some file. This is a ...
1
vote
0answers
123 views

Easiest and Fastest way to Embed a Python Script into C?

I have been looking at the Python/C API for embedding my python script into C. I want to know if there is an easy (or simpler) way to embed my python script without having to get too involved in the ...
1
vote
1answer
840 views

Running Python from Visual C++ code (Embedded Python)

I have this Visual C++ code, plus Python embedded in it, when I try to run external Python code using the below code, I get the error in the Debug mode: Unhandled exception at 0x77cf15de in ...
2
votes
1answer
983 views

How to redirect python interpreter output and catch it in a string in C++ program?

i am using python C++ API to run python commands from C++ program. I want to catch all the python output to a string, I've managed by the following redirection, to catch pythons stdout and stderr ...
6
votes
5answers
2k views

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 ...
1
vote
5answers
533 views

Extending Python: pre-load my C module

I'm trying to extend Python interpreter by a few C functions I wrote. From reading docs, to expose those function the user has to import the module encompassing the functions. Is it possible to load ...
3
votes
2answers
350 views

(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 <Python.h> #include "iostream" int main(int argc, char *argv[]) { ...
3
votes
1answer
501 views

Why is this 'from-import' failing with PyRun_SimpleString?

I am working on a simple(?) embedded Python project. I have a custom package that has been installed into site-packages with 'setup.py install', e.g.: in C:\Python27\Lib\site-packages\: mypackage\ ...
4
votes
1answer
1k views

How do I find out why importing failed with PyImportModule?

I have this code in a C application that's embedding Python (2.7.1): { PyObject *user_dict; PyObject *user_func; PyObject *result; PyObject *header_tuple; PyObject *original_recipients; PyObject ...
5
votes
1answer
1k views

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 ...
4
votes
1answer
2k views

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 <Python.h> //// Definition of 'emb' Python module //////////////////// static PyObject* emb_foo(PyObject ...
2
votes
2answers
471 views

Python / C-Api: Add class to module

Im currently trying to embed the python interpreter into my application. Because my application uses the Poco API for logging, I want to make it accessable through the logging module in python too. ...
3
votes
1answer
950 views

Printing a variable in an embedded Python interpreter

I have written a small C program that embeds Python. I'm setting it up correctly using Py_Initialize() and Py_Finalize(), and am able to run scripts either using PyRun_SimpleString or ...
1
vote
1answer
179 views

“overloading” doesn't work with stderr

/*---------------stdcallbk_module.h---------------------*/ #ifndef STDCALLBK_MODULE_H #include <Python.h> #define STDCALLBK_MODULE_H // Type definition for the callback function. typedef void ...
1
vote
2answers
984 views

Tried to embed python in a visual studio 2010 c++ file, exits with code 1

I am trying to embed some python code in a c++ application i am developing with ms visual studio c++ 2010. But when i run the program, it exits with code 0x01 when i call Py_initialize(). I dont know ...
3
votes
1answer
737 views

Embedding python + numpy code into C++ dll callback

I am new of python embedding. I am trying to embed python + numpy code inside a C++ callback function (inside a dll) the problem i am facing is the following. if i have: Py_Initialize(); // some ...
5
votes
1answer
2k views

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) ...