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

_ctypes.cpython-39-x86_64-linux-gnu.so: undefined symbol: PyFloat_Type in embedded Python loaded with dlopen

I am using embedded Python (3.9) in ubuntu 20.04 and trying to import ctypes which produces the error _ctypes.cpython-39-x86_64-linux-gnu.so: undefined symbol: PyFloat_Type. I am compiling a shared object, which is loaded dynamically using…
TCS
  • 5,790
  • 5
  • 54
  • 86
4
votes
0 answers

Py_EndInterpreter in Python 3 is very slow

The application I am working on recently migrated from embedding python 2.7 to python 3.8 We noticed a significant slowdown when calling Py_EndInterpreter in Python 3.8, when using many sub-interpreters. Looking at the CPU usage I can see that all…
4
votes
0 answers

Releasing the GIL in PyBind11 for multithreading in Python with OpenMP

I am using Pybind11 and trying to use OpenMP in it. I call a c++ function from Python using the PyBind interpreter and GIL, then I compute a multithreaded for loop with OpenMP in c++, in which I call within each thread a python function. To do so, I…
Joachim
  • 490
  • 5
  • 24
4
votes
1 answer

How to interrupt python interpreter embedded in C++ application

We have a C++ QT application, we embedded python in it. We provided two interfaces to the user 1. Execute file 2. Stop execution. We execute a python file in a non GUI thread, using PyRun_FileExFlags. We would like to interrupt python…
srinivas M
  • 55
  • 7
4
votes
2 answers

Embedding python in C, undefined symbol: PyExc_ImportError

I am trying to write a plug-in for Audacious Media Player that loads a python module. The python embedding code is from the python-2.6 source(embed/Demo). This compiles with the command line, gcc -o demo demo.c -lpython2.6 -lm…
madura
  • 41
  • 1
  • 2
4
votes
1 answer

"No module named site" when embedding python in c++ in Visual studio

there are similar questions on StackOverflow, but I couldnt find any helpful. I am embedding python in c++ in visual studio. My python is in anaconda, and the directory for anaconda is c:/anaconda2, my code is very simple #include int…
Allanqunzi
  • 3,230
  • 1
  • 26
  • 58
4
votes
0 answers

Unable to import builtin modules from embedded interpreter (Windows only)

As a heads up, this question may appear to be a duplicate of embedding python module error Embedding Python 3 - no builtins? but I think my issue is different. I'm running a Python 3.4 interpreter from an MSVC compiled C++ application, and I'm…
mynameisjohnj
  • 421
  • 4
  • 12
4
votes
1 answer

Call multiple python functions from different directories

I have some code that will go to a directory (Folder 1 for demonstration purposes), then call a function called function in the file python_function.py. The code looks like this: #include #include #include int…
Ben Hollier
  • 585
  • 2
  • 11
  • 32
4
votes
1 answer

Pass std::string into PyObject_CallFunction

When I run pResult = PyObject_CallFunction(pFunc, "s", &"String"), the python script returns the correct string. But, if I try to run this: std::string passedString = "String"; pResult = PyObject_CallFunction(pFunc, "s", &passedString) Then convert…
Ben Hollier
  • 585
  • 2
  • 11
  • 32
4
votes
2 answers

Mavericks: Compile Python Interpreter into a static lib

I want to embed the Python 3.3 interpreter into Mac OS 10.9 Cocoa app to add some Python functionality. From what I've read from another StackOverflow Q&A, it would be best to create a static library (references in footer) than a dynamic…
Alerty
  • 5,945
  • 7
  • 38
  • 62
4
votes
1 answer

Conflict between two linux shared objects defining the same function name

My problem deals with Python, Qt, PyQt and other stuff, but the question is actually about how Linux's ld.so actually works. THE QUESTION If a program loads two different shared libraries which both have the same entry point name (i.e. they both…
deStrangis
  • 1,912
  • 1
  • 18
  • 25
4
votes
1 answer

second python execution fails

I'm having a problem embedding the python 3 engine for an app that need to run custom scripts in python. Since the scripts might be completely different, and sometimes user provided, I am trying to make each execution isolated and there is not need…
The Dark Brainer
  • 694
  • 6
  • 16
4
votes
1 answer

Building Boost Python Debug

I am definitely not a bjam expert, so pardon my ignorance if it's something really stupid. I am trying to build a debug version of boost::python using this tutorial. I have built Python 3.3.0 in my folder C:\Development\Python-3.3.0. The build is…
emartel
  • 7,712
  • 1
  • 30
  • 58
4
votes
2 answers

Python code in C++

I want to use some Python code in my C++ framework to plot some statistics. I have already found the following posting (about how to embedd python in c++) but following the instructions did not lead to success: Embed python code in C++ (Windows +…
bobby
  • 115
  • 8
4
votes
1 answer

how to pass command-line arguments as a string to an embedded Python script executed from C++?

I have a C++ program which exposes a Python interface to execute users' embedded Python scripts. The user inserts the path of the Python script to run and the command-line arguments. Then the script is executed through…
rmbianchi
  • 6,241
  • 6
  • 26
  • 27