I’m trying to embed Python in C++. This is my Python file (with the name EmbedTest.py): This is my C++ file (with the name EmbedTest.cpp and located in the same folder as EmbedTest.py) Compiling is fine. I use the flags suggested by python3.6-config –cflags. Hence gcc -c -I/home/MyFolder/anaconda3/include/python3.6m -Wno-unused-result -Wsign-compare -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -O3 -pipe -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix -fuse-linker-plugin
Tag: c++
OSError: [WinError 193] %1 is not a valid Win32 application while reading custom DLL in python with CTypes
I am trying to write code that wraps a C library in python. I am planning on using CTypes to do it and I used visual studio to compile my DLL. I started with a simple function and I added the following in a header within Visual Studio that was then built to a DLL My python wrapper is the
Access a global pointer in C from python using ctypes
I know that if I have a global variable (let’s say a double called N) I can read it using: but what if my variable is a pointer? How can I read the contents of the pointer in to a python list? To be clearer, N is declared in the following way in the shared library: Answer Given this (Windows)
CUDA(GPU) as OpenCV backend
Am trying to use CUDA as backend for dnn module provided in opencv-4.1.1 , I have build opencv with CUDA enabled, nvidia drivers and CUDA is properly placed on system, here am using manjaro as development platform. am trying to load pre-trained YOLOv3 weights using cv2.dnn module, But it uses CPU as defualt inference engine, but am trying to use
Calling Python function with arbitrary number (not known at compilation time) of parameters from C++
I need to make a call from C++ to a Python function of the form Requirement: I shouldn’t modify the Python function. They are provided by users and should have that signature for consistency. The Python.h interface provides (quoting from the link to not make you have to open another page): PyObject* PyObject_CallFunction(PyObject *callable, const char *format, …) Return value:
How to fix “SystemError: returned NULL without setting an error” in Python C Extension
Tools: Python3.7 (64 bit), Visual C++ 10.0 I am trying to create a C extension for Python. To start, I am testing a simple C code which prints a string and invokes the Sleep() function inside a for loop. However, when I make a simple call to this C function, named gen_nums, from Python, I get the following error: “SystemError:
Python boost to-Python converter for class already registered second conversion method ignored
I have next class (it was simplified): I have python boost module: Python script is called from dll library and uses container from pyd py_classes. When dll-library is called first time std_vector_value type is used without any problems. When I reload dll-library inside executable I get next warning: So, it means: When dll-library is loaded first time, to-python converter is
Logging with Python, ROS, and C++
I have a codebase of Python and C++ code, including heavy use of ROS. Logging is done throughout the Python code with both system logger and rospy logging — contrived example: As for C++ code we need to add logging, probably with glog but I’m open to other options. Is there a way to integrate the various loggers into one
How to model struct that contains reference to it’s definition in python through ctypes?
trying to wrap struct the reference it’s definition as below foo.c how to model that, for example foo.py of course python doesn’t interpret that, I could use c_void_p instead of pointer(Foo), and cast it’s value as follow but, is there a way to model that struct in a python class? Answer From [Python.Docs]: ctypes – Incomplete Types: … . In
Reading a C-struct via sockets into python
On an embedded device running a C application, I have defined this struct: On request, I send this struct via sockets: and read it from a Python script on my desktop: This is the data printed to console on my desktop: How can i reassemble the data into a YourStruct? Note that the embedded device uses little endian, so I