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

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

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…
7
votes
2 answers

Python Embedding: PyImport_Import not from the current directory

using the next line pModule = PyImport_Import(pName); Only load modules from the current directory. But what I want to load from somewhere else? Is there a neat way to do so? PyRun_SimpleString("import sys\nsys.path.append('')"); Works, but…
Guy L
  • 2,824
  • 2
  • 27
  • 37
6
votes
1 answer

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 python glue // python…
Pa_
  • 641
  • 1
  • 5
  • 17
6
votes
0 answers

Extending and Embedding Python in C++: Is PyImport_AddModule required to import extension module before importing python script?

I am embedding Python in a C++ application and I also need to call back in to the C++ code from Python. I have been able to do this with the following simple example but I'm having a weird problem in my C++ application. Module definitions... static…
naybot
  • 61
  • 3
5
votes
1 answer

Does the Python 3 interpreter leak memory when embedded?

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…
5
votes
1 answer

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 *working_recipients; if (!Py_IsInitialized()) { …
Tony Meyer
  • 10,079
  • 6
  • 41
  • 47
5
votes
0 answers

Embedding Python with NumPy & SciPy in a macOS app

Is there a more streamlined process in embedding a Python interpreter, with numpy and scipy libraries, in a macOS application project using XCode? I suppose, to be more specific here, embedding Python, with numpy and scipy libraries, that does not…
JDBones
  • 495
  • 1
  • 7
  • 18
5
votes
0 answers

Calling Py_EndInterpreter from a C worker thread

The deprecation of Python's PyEval_ReleaseLock has introduced a problem in our codebase: We want to terminate a Python interpreter from a C callback function using Py_EndInterpreter So to do that, Python's Docs say that you must hold the GIL when…
5
votes
1 answer

Disable built-in module import in embedded Python

I'm embedding Python 3.6 in my application, and I want to disable import command in the scripts to prevent users to import any python built-in libraries. I'd like to use only the language itself and my own C++ defined modules. Py_SetProgramName…
kovacsv
  • 687
  • 4
  • 14
5
votes
2 answers

pythonnet Embedding Python in .net example failing to load module

I'm trying to run the Embedding Python in .NET example from https://github.com/pythonnet/pythonnet. I've followed troubleshooting articles to set the proper %PYTHONPATH% and %PYTHONHOME% to my anaconda environment in the program base…
mstockfo
  • 91
  • 1
  • 8
5
votes
1 answer

youtube-dl only extract playlist info

ydl = youtube_dl.YoutubeDL() with ydl: r = ydl.extract_info("myplaylist", download=False) # don't download, much faster print(r['uploader'],r['title'],r['thumbnail']) code output like this [youtube:playlist] Downloading playlist…
stackrangerflow
  • 51
  • 1
  • 1
  • 6
5
votes
1 answer

PyImport_ImportModule, possible to load module from memory?

I embedded python in my C++ program. I use PyImport_ImportModule to load my module written in a .py file. But how can I load it from memory? Let's say my .py file is encrypted, so I need to first decrypt it and feed the code to python to execute.…
kchkg
  • 147
  • 3
  • 13
5
votes
1 answer

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\ __init__.py subpackage\ …
djangodude
  • 5,362
  • 3
  • 27
  • 39
4
votes
1 answer

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 PyRun_SimpleFile. However, I don't know how mimic the behavior of…
FizzBuzz
  • 764
  • 6
  • 16
4
votes
0 answers

Boost-Python: crash when executing script from file

When my console application tries to execute boost::python::exec_file() it hangs for a second and then crashes. It can execute the boost::python::exec without problems. I tried not using then boost bindings and execute from the python api directly…
mXed
  • 71
  • 8
1 2
3
20 21