Questions tagged [cythonize]

Use this tag for questions about the compilation of python extension modules based on cython using "cythonize". Use the more generic [cython] tag if the question isn't about the actual compilation process.

The cythonize function can be imported from Cython.Build and is used to compile extensions for python. It is responsible for compiling the .pyx (cython files) to .c files.

The cython "Compilation" documentation contains several examples how to include cythonize in the build process for python modules.

342 questions
5
votes
1 answer

How to use Cython on Windows 10 with python 3.8

I want to know how correctly convert py documents to C with help Cython But all the time a have some error. D:\Cython\test4>python setup.py build_ext --inplace running build_ext Traceback (most recent call last): File "setup.py", line 4, in…
Alex97
  • 73
  • 2
  • 9
5
votes
1 answer

Cython C-level interface of package: *.pxd files are not found

In a nutshell I try to compile a cython extension called extension2 that cimports a file extension from a self-created package. When building extension2, I get the error that extension.pxd is not found though this file is exactly at the sepcified…
Samufi
  • 2,465
  • 3
  • 19
  • 43
5
votes
1 answer

Understanding inconsistent cythonized code behavior - PyQt5 vs. PySide2

While cythonizing some PyQt5 code, I was encountering TypeError: method() takes exactly 1 positional argument (2 given). Strangely, replacing PyQt5 with PySide2 seems to not cause this behavior. I was hoping someone could help me understand why this…
Soham Patel
  • 53
  • 1
  • 3
5
votes
1 answer

Can I achieve precise control over location of .c files generated by cythonize?

I am using Cython as part of my build setup for a large project, driven by CMake. I can't seem to get Cython to generate the .c files in a sensible location. My file layout: C:\mypath\src\demo.py # Cython source…
Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
5
votes
2 answers

How to build a compiled module for multiple Python versions and platforms

I have build a Python 3 module for my own process. I use cython to compile and wrap C++ sources. I have a Linux (Debian Jessie) machine with Python 3.4 and so cythonize make me a Processing.cpython-34m.so and copy it to…
doom
  • 3,276
  • 4
  • 30
  • 41
5
votes
1 answer

How to pass string from Python3 to cythonized C++ function

I am trying to understand how to pass string values between Python3 and cythonized C++ function. However I am unable to build the library with Cython. In particular, I didn't understand how to declare the string return value and string parameter in…
gc5
  • 9,468
  • 24
  • 90
  • 151
4
votes
1 answer

Cythonized function with a single positional argument is not possible to call using argument name

Long story short, I want to cythonize my python code and build .so files to hide it from the customer. Take this simple function: def one_positional_argument(a): print(a) and my setup.py which builds the .so file from setuptools import setup,…
4
votes
1 answer

Cython exception propagation for cdef functions returning multiple values

I have a cdef function returning an (int, int) tuple. I need to propagate exceptions and must therefore specify a return type for exceptions. Since my function never returns negative values, this could e.g. be (-1, -1). With the standard syntax…
Samufi
  • 2,465
  • 3
  • 19
  • 43
4
votes
2 answers

'Exception ignored in:' cython extension classes and their `cdef` methods

I have some cython classes, and in their cdef methods, I have assert statements. However, instead of getting an AssertionError that I can catch, for example, I get Exception ignored in: and I cannot catch it (pytest reports this as warnings as…
Fawaz.D
  • 118
  • 9
4
votes
1 answer

How to remove -pthread compiler flag from cython setup file

In linux environment, when I run the setup script for cython, I get gcc -pthread -B /apps/.../compiler_compat -Wl,-sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/ap...... for my case, I want to remove the…
Ong Beng Seong
  • 196
  • 1
  • 11
4
votes
0 answers

How can I wrap the C++ library with Cython?

I have some code from a colleague using cython.weave to wrap a function from a C++ library: def partialsort(a, K): support_code = "#include " code = "std::partial_sort (&ak(0), &ak(K), &ak(N));" N = len(a) ak = a.copy() …
Thomas Arildsen
  • 1,079
  • 2
  • 14
  • 31
4
votes
1 answer

Cython class AttributeError

I have started to experiment with Cython and ran into the following problem. Consider the following class representing a vertex in the 3D space: #Vertex.pyx cdef class Vertex(object): cdef double x, y, z def __init__(self, double x, double…
Botond
  • 2,640
  • 6
  • 28
  • 44
4
votes
0 answers

how to exclude .py and .pyc files when building a cythonized conda package?

I have a setup.py script (see below) that cythonizes my python package. I also have a meta.yaml (see below) to build a conda package. How do I avoid that the .py and .pyc files are bundled inside the conda package (.tar.bz2)? I already tried some…
dcatteeu
  • 481
  • 3
  • 10
4
votes
2 answers

Make executable file from multiple pyx files using cython

I am trying to make one unix executable file from my python source files. I have two file, p1.py and p2.py p1.py :- from p2 import test_func print (test_func()) p2.py :- def test_func(): return ('Test') Now, as we can see p1.py is dependent…
Dinesh Ahuja
  • 925
  • 3
  • 15
  • 29
4
votes
0 answers

Why can I not derive a Cython cdef extension type from another?

There might be something obvious I'm doing wrong, but I just can't get an extension type to derive from another, even in this simple example: $ cat a.pyx from b.py import MyClass cdef class NewClass(MyClass): pass $ cat b.pyx class…
E. T.
  • 847
  • 10
  • 26
1
2
3
22 23