335 questions
7
votes
1
answer
2k
views
`PyTuple_Pack` segfault
I have a function foo in a Python Extension Module that should return a tuple of ints to Python. This can be easily done using Py_BuildValue:
static PyObject*
foo(PyObject* self, PyObject* args)
{
...
0
votes
0
answers
980
views
How to pass a python bytes object to a C++ extension?
I am trying to pass a numpy array to a customized C++ extension but somehow I got a segmentation fault. Here I made a simplified version of my code.
On the C++ side, I simply parse a bytes object ...
3
votes
0
answers
382
views
Cython: avoid compiling all C/C++ files on each extension. Objective: distribute in PyPi
The Cython project I am currently working on includes some 20 C++ files that act as C++ implementation. On top I have built three Extension Modules written in Cython, each of them capturing different ...
6
votes
0
answers
1k
views
Python C Extension: Fatal Python error: PyThreadState_Get: no current thread
I am trying to build a C based Python extension that uses a ffmpeg libraries. Since there are a bunch of libraries I have to import. I used CMake. I followed the instructions from python doc
The ...
2
votes
1
answer
2k
views
Import functions from dll (programmed in C++) into Python script when the dll has an embedded Python interpreter
I wrote a library (dll) in c++ that uses an embedded Python interpreter.
Executing Python scripts in the embedded interpreter works fine when the library is used by a c++ program.
If I call the ...
0
votes
1
answer
333
views
Issue with Linking Python C Extension to Another Library
I am in the process of developing a Python extension to allow a script running on a Raspberry Pi to control a sensor. The sensor manufacturer provided my organization with the source code to their C ...
6
votes
1
answer
7k
views
How to generate .pyi files for a compiled Python extension?
I build a compiled Python extension (.pyd file) with C++ and pybind11. I would like to generate a single Python interface .pyi file for my .pyd file.
There are a few similar questions referring to ...
0
votes
1
answer
162
views
Python crashes on returning an C++ map value
i am writing a Test to keep Data in a C++ map. I am using the Python C-Api.
Adding int values and getting the length of the map is no problem.
But when i get a value from the map and want to return it ...
1
vote
0
answers
325
views
Very different size of *.so and *.pyd, why?
I managed to build *.pyd library. Sweat, blood, tears and gore aside, it turned out to be about 4 (four) times smaller than the corresponding *.so library.
While the code seems to work, I cannot ...
0
votes
1
answer
756
views
Linking with Apache Portable Runtime on MS Windows
I'm trying to build a Python extension which links to APR. And this time it's on MS Windows... (It works on Linux).
Here's where the build fails, the command, and the output formatted for ...
-1
votes
1
answer
306
views
PyObject_Call segfaults when invoked with bound method
PyObject_Call segfaults when it is called with an instance of a bound method, but works fine when invoked with regular (unbound) procedures or with an instance of a class that implements __call__, or ...
2
votes
0
answers
190
views
Extending Python with C on Windows - ImportError: DLL load failed: %1 is not a valid Win32 application
So, I'm interested in communicating between a C program and a Python program so that I can neatly send tasks and data between the two.
I figured I'd go ahead and start with this guide. In this guide ...
5
votes
1
answer
10k
views
How to return a list of ints in Python C API extension with PyList?
I am building a Python extension (.pyd) using Visual Studio 2015 C++ project and Python 2.7 32bit.
This is my .cpp file:
#include <Python.h>
static PyObject* GetTwoInts(PyObject* self, ...
4
votes
0
answers
791
views
Cross compile Python extension from Linux to Win using MingW
I am trying to cross compile a software on a Linux machine targeting a Windows system using Mingw.
Baiscally in the software compilation a Python extension is built and here we have the problems:
...
4
votes
0
answers
3k
views
Shared library distributed in python wheel not found
I have a python module which contains a C++ extension as well a shared library on which the C++ extension depends. The shared library is picked up by setuptools as an extra_object on the extension. ...
1
vote
0
answers
292
views
Python extension build chokes on `std::unique_ptr` on Mac
I have a toy project that's implemented as a C++ library and exposed to Python using a Cython wrapper. After not touching the project for a few months, I tried to build it from scratch today and got ...
1
vote
1
answer
859
views
Trouble with DateTime object methods in C++ extension
I'm working on a C++ extension for Python 3 and trying to pass a DateTime object to my function. the PyDateTime_Check function seems to work and returns true, but when I try to get the year from the ...
0
votes
1
answer
355
views
My PyCFunction works the first time but leads to a segfault after successive iterations
I want to write a python object in c that holds a numpy vector (two actually, but just one in this minimal example).
To begin with, I just want to create an object with a numpy array and see that I ...
1
vote
1
answer
4k
views
How Can I import a Data set in Jupiter notebook (AD_Data.xlsx) data got xlsx extention
Tried all the possible options
like
import pandas as pd
df = pd.read_csv('AD_Data')
data = pd.ExcelFile("AD_Data")
xl_file = pd.ExcelFile(AD_Data)
dfs = {sheet_name: xl_file.parse(AD_Data) for ...
1
vote
1
answer
121
views
Multifile C Python Extension Organization Issue
Currently, I am trying to write a C Python extension. Specifically, I am trying to create a python module that has a couple of classes in it. Basically, I want it to look something like this:
...
1
vote
1
answer
233
views
Make C-Extension calls "green" in python
I have some python code which is heavily dependent on greenlets. I can use either gevent or eventlet.
I have packaged some sections of the code in a C-extension but these calls do not yield to other ...
1
vote
1
answer
230
views
In Python 3 extension written in C++, how to pass a wstring object to Python code?
I'm trying to build a Python extension with C++ 14. When the module is initialized in Python, I ask caller giving me a callback function which take a string as input.
When a function in the module is ...
0
votes
1
answer
336
views
Incorrect message length when using C python api
I'm trying to extend libhydrogen (open source found here: https://github.com/jedisct1/libhydrogen/) to support calls to the underlying library in Python. However, I ran into a strange issue.
...
1
vote
1
answer
2k
views
python3 stack smashing - python extending with c
I am writing a python extension in C. There is a library for a raspberry hw dev board in C so I'm using that. So I'm exporting a function from C to python and at the end of the call, python falls over ...
2
votes
2
answers
1k
views
Numpy C extension: Access PyObjects in a PyArrayObject
I created a pandas dataframe with pd.DataFrame({"A": ["dog", "cat"]}) and sent to a c extension the resulting numpy array. In C, I do:
PyArrayObject * pArray = (PyArrayObject *) pArrayObj;
...
2
votes
1
answer
500
views
How to change function parameter values in a Python 3 C extension?
I can't figure out how to change the value of a parameter passed from Python to C.
PyArg_ParseTuple (args, "Os", &file_handle, &filename)
will let me get file_handle as a PyObject *. Is ...
0
votes
1
answer
87
views
How to handle concurrency if C/C++ Python3 extension hosting a http server and calling python code as request handler?
I try to create a Python extension which will host a HTTP server. When a particular request coming in, the extension calling a Python code from the extension consumer to handle the request. Since HTTP ...
1
vote
1
answer
647
views
Compile file with two separate libraries in Cython
I wrote a library in Cython that has two different "modes":
If rendering, I compile using GLFW.
If not rendering, I compile using EGL, which is faster, but I have not figured out how to render with it....
3
votes
0
answers
151
views
passing python3 file stream to C++ extern function
Okay there, i have some code in python that opens a file -> process it -> and writes data to other file.
def ELECrypt(myFile, outFile, code):
Code = list(bytes(code,'utf-8'))
with open(myFile,...
5
votes
2
answers
3k
views
Use Setuptools with C Extension as part of package
I wrote a C Extension to access an error message for a camera from a proprietary library. The structure is
setup.py
dicamsdk\
|---__init__.py
|---control.py
|---pcoError.c
with setup.py
from ...
26
votes
3
answers
12k
views
How to build and distribute a Python/Cython package that depends on third party libFoo.so
I've written a Python module that depends on some C extensions. Those C extensions depend in turn on several compiled C libraries. I'd like to be able to distribute this module bundled with all the ...
2
votes
1
answer
800
views
Segmentation fault on Python extension method
I have been working on a Python C/C++ extension, I managed to get everything working so far except a method that adds two structures called "int_obj" that have an integer inside and returns a new ...
0
votes
1
answer
510
views
Python C extension with executable dependency
I have this C SDK that I'm working on creating a Python extension for. The C SDK documentation says that it expects a ffmpeg executable in it's working directory. My current project structure is:
my-...
-1
votes
1
answer
805
views
`unique_ptr`s causing 'undefined symbol' in python extension
I have a C++ project which uses a couple of c++14 features including std::make_unique.
The project compiles and runs fine and has done for a while however, now I am trying to add a python interface ...
0
votes
1
answer
381
views
Building 64 bit Python extension on Windows tuple : undeclared identifier
I work on 64 bit windows with 64 bit python 2.7 and i am trying to compile my first c++ extension for python.
At first i tried to use mingw but ran into many linker errors, so now i use c++ for python ...
0
votes
1
answer
508
views
What's the fastest way to use C/C++ in Python?
What is the fastest way to call C/C++ functions and use C++ classes?
There are various methods to do this such as Python Extension Module (Python.h), Cython, SWIG, Boost, and etc.
I've already ...
3
votes
0
answers
428
views
How to convert a PyCapsule into a ctype?
I am trying to get a python c extension to work. The extension is used in a package which registers a python callback with the extension and then the extension calls it to communicate with the python ...
2
votes
2
answers
661
views
Python extensions with C: staticforward
So I needed to use the code of the subprocess module to add some functionality I needed. When I was trying to compile the _subprocess.c file, it gives this error message:
Error 1 error C2086: '...
1
vote
1
answer
619
views
Pydev tags import as “unresolved import” all compiled extensions
PyDev with Python3.5 seems unable to recognize imports from c-compiled extensions, including packages compiled via Cython.
I am working on an up-to-date debian/stretch machine with a stripped-down ...
0
votes
3
answers
385
views
Execute Regardless of the Type of Exception
I would like my program to exit regardless of the type of the exception that occurred. However, depending on the type of the exception, I want to log a different error message. How could I achieve ...
0
votes
0
answers
40
views
When building boost.python why do some files get 'python' in the name and others get 'python3'?
For example, if I run the following command:
bjam --toolset=msvc-14.0 address-model=64 --with-python python-debugging=off threading=multi variant=debug toolset=msvc-14.0 link=static --stagedir=stage\...
0
votes
0
answers
61
views
How can I expose C++ classes in a Python extension? (Without resorting to boost.python or swig or cython)
I've followed this video tutorial on setting up a very basic C++ extension for python using Visual Studio. It's very straightforward and works quite nicely.
https://www.youtube.com/watch?v=y_eh00oE5rI
...
1
vote
1
answer
421
views
Python C Extension: PyEval_GetLocals() returns NULL
I need to read local variables from Python in C/C++. When I try to PyEval_GetLocals, I get a NULL. This happens although Python is initialized. The following is a minimal example.
#include <...
11
votes
3
answers
2k
views
How can I write a C function that takes either an int or a float?
I want to create a function in C that extends Python that can take inputs of either float or int type. So basically, I want f(5) and f(5.5) to be acceptable inputs.
I don't think I can use if (!...
5
votes
1
answer
1k
views
Bundling C++ extension headers with a Python package source distribution
I'm writing a Cython wrapper to a C++ library that I would like to distribute as a Python package. I've come up with a dummy version of my package that looks like this (full source here).
$ tree
.
├──...
1
vote
0
answers
81
views
Cython generated module can't be used because of undefined symbol
The python extension lsblib.so is created by cython and distutils, the build command generated from distutil is as following:
/gpfs/software/openlava_sqa/3.3.3/etc/../include/lsbatch.h:1681: warning: ...
2
votes
0
answers
2k
views
How do I find out if/where xlsxwriter is on my system (for python)?
I am attempting to use the xlsxwriter package to write and image to an eXcel file, but I keep getting the 'No module name 'xlsxwriter' error on the import statement. I am on a closed network, so I am ...
0
votes
1
answer
364
views
two-dimensional python dict with shared memory
I need to load data from a csv file or an excel sheet (with rows and columns) into a two-dimensional python dict. For example, if the data in an excel sheet looks like this:
name age gender ...
5
votes
1
answer
14k
views
how to write setup.py to install python extention (xxx.so file) built by SWIG?
Using SWIG to build python extensions (xxx.so) is easier than distutils. You don't need to write a wrap.c program to wrap your original c program. So I'd like using SWIG than Distutils. But There is ...
1
vote
0
answers
134
views
Cython make a template class have error
# distutils: language = c++
# distutils: sources = cppcode.cpp
from libcpp.string cimport string
cdef extern from "cppcode.h" namespace "mynamespace":
cppclass LinkedList[T]:
LinkedList ()
...