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
3
votes
1 answer

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, Python 2.7.2 and gcc. Here the codes: #include…
Janil
  • 81
  • 1
  • 7
3
votes
1 answer

How can I check if a thread holds the GIL with sub-interpreters?

I am working on some changes to a library which embeds Python which require me to utilize sub-interpreters in order to support resetting the python state, while avoiding calling Py_Finalize (since calling Py_Initialize afterwards is a no-no). I am…
Los Frijoles
  • 4,771
  • 5
  • 30
  • 49
3
votes
2 answers

Cannot install jupyter on windows: No module named '_pyrsistent_version'

I use "Windows x86-64 embeddable zip file" python 3.7.3 distribution in Windows 7 SP1 x64 to run Python. I have added pip script and it's working. I tried to install jupyter 1.0.0 using pip. This error…
Hamid Rouhani
  • 2,309
  • 2
  • 31
  • 45
3
votes
0 answers

Approach to multi-threaded, multi-processing, async python embedded in c++ with PyBind

I wanted to do a stack inquiry before I do a deep dive tomorrow and start trying out every option under the sun. We have an application that we've embedded python inside with PyBind 11. In the current implementation application events are triggering…
Jeef
  • 26,861
  • 21
  • 78
  • 156
3
votes
0 answers

C++, Python embedding: Importing torch/sklearn library on embedded python code throws a DEBUG: caught signal to interrupt error

I have written a program in C++ which uses python embeddings in order to call a python module, which utilizes the numpy and pytorch libraries. When using solely the numpy library I can successfully call and return from the module without any…
3
votes
1 answer

Import modules from embedded Python script

tl;dr How do I import a Python module from an embedded Python script, so that the imported module can use the global variables and functions provided by the host system? I am writing a Python script for some system (written presumably in C++). I…
Headcrab
  • 6,838
  • 8
  • 40
  • 45
3
votes
1 answer

Extracting value from Python after it's embedded in C++

I have the following shortened program that embeds Python (it's stripped of all error handling, etc for shortness). It creates Python function as a string (which is required for my problem at hand) and then tries to call it and get whatever it…
Dmitry Torba
  • 3,004
  • 1
  • 14
  • 24
3
votes
1 answer

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 output: #python script ,…
alexpov
  • 1,158
  • 2
  • 16
  • 29
3
votes
2 answers

Errors using sys from Python Embedded in C++

I am using Eclipse to run C++. In my code,I use a High Level Embedding of Python to run a function. When I try to use sys and import it. I get the error: Fatal Python error: no mem for sys.argv CODE: #include #include…
Y. Reznichenko
  • 153
  • 2
  • 13
3
votes
0 answers

Embedding Jupyter in Qt Application

I have a Qt application with an embedded Jupyter QtConsole. This is the code that I use to create the Jupyter console: from qtconsole.rich_jupyter_widget import RichJupyterWidget from qtconsole.inprocess import QtInProcessKernelManager class…
3
votes
1 answer

Program with embedded python fails to start with python 2.7.11 amd64

I have a windows program that has python embedded in for scripting purposes If I install Python 2.7.10 64 bit (python-2.7.10.amd64.msi), and run the program, it works fine. If I install Python 2.7.11 64 bit (python-2.7.11.amd64.msi), and run the…
Simon Callan
  • 3,020
  • 1
  • 23
  • 34
3
votes
1 answer

Call python script from c++ without loading the file each time

I have a python script that I need to call lots of times (around 160000 times) and while I can do this in less that a second with hard C++ code, if I try to load and call a python script to do this, it will probably take hours! I think that if I…
Ben Hollier
  • 585
  • 2
  • 11
  • 32
3
votes
1 answer

ImportError and PyExc_SystemError while embedding Python Script within C for PAM modules (.so files)

I'm trying to write a demo PAM module in C, which uses Embedding Python in C concept to run a script written in python (2.7), inside pam_sm_authenticate() function, which is written in C file (pam_auth.c). This is the python script: test.py import…
stitchesguy90
  • 373
  • 4
  • 10
3
votes
1 answer

Passing a c++ vector to python and back

I am using a c++ code to do some simulations on an image. At some point, I need to label the image clusters, for which I want to use python ndimage.label (because it is almost 10 times faster than my labelling code). However, I am very new to python…
Lalit
  • 45
  • 7
3
votes
1 answer

Boost python, calling c++ functions from python when embedded

I currently have the following: namespace py=boost::python; //C++ void f() { std::cout << "hello world\n"; } //I am not precious about this, if it can be done without a module that would be great BOOST_PYTHON_MODULE(test) { py::def("f",…
111111
  • 15,686
  • 6
  • 47
  • 62