Questions tagged [cython]

Cython is a superset of the Python language for quickly generating Python C extensions.

Cython is a superset of the Python language for quickly generating Python C/C++ extensions. Cython is a pidgin language of Python and C/C++. Unlike pure Python, Cython code is not directly interpreted by the Python interpreter, but is instead used to generate C/C++ code. The generated C/C++ code can then be compiled into a C/C++-extension, which then can be imported by Python code.

Cython syntax was originally based on Python 2, with added type declarations à la C/C++, however, its syntax now supports both Python 2 and 3 language features. Additionally, Cython is capable of generating C/C++ extension code compatible with either Python 2 or Python 3. Its syntax now allows the use of advanced C++ constructs such as template and stl container. Finally, thanks to static typing, Cython code generally executes much faster than Python code.

Cython is freely available under the open source Apache License.

The latest release of Cython is 3.0 alpha 5 (released 2020-05-19). Cython is available from the PyPI package index repository.

5220 questions
3
votes
0 answers

Python Pypi package installation works on Linux but not in Windows

Introduction I'm creating a package to solve route problems. I'm using Cython in the heavy math parts to increase the speed. In Linux SO (Ubuntu 18.04) everything works perfect. But in Windows 10 it's impossible to install it via pip install…
Rubiales Alberto
  • 143
  • 3
  • 12
3
votes
1 answer

Cython: Dynamically linking with a dll/so

I'm working with an API which is distributed as a dll/so file that I need to dynamically link with my python program. To accomplish this, I want to use Cython. I have been able to, in the past, link with the dll statically. This works well, except…
Josiah
  • 3,266
  • 24
  • 24
3
votes
0 answers

Cython: Is there a use case for compiling multiple pyx-file into one extension module

I was looking for a method to compile multiple pyx-files using only setup.py file. The solution was found in the official documentation: ext_modules = [Extension("*", ["*.pyx"])] setup(ext_modules=cythonize(ext_modules)) This will compile all…
Felix Hohnstein
  • 459
  • 5
  • 13
3
votes
0 answers

Using custom cython modules in colab

I'm trying to run some code python code in Google colab. This code uses some custom modules I wrote, some of which were written in cython. On my local machine, I'd normally compile the cython code first before running my main python script. What is…
user360798
  • 31
  • 2
3
votes
0 answers

How to use Cython functions in C/C++ and Python within the same project?

I've been learning about Cython recently. I'm still a beginner, but I'm excited about the prospect of using it in the future. In my mind, Cython has two main uses: Making Cython or C/C++ functions accessible from Python. See: Calling C…
JacKeown
  • 2,780
  • 7
  • 26
  • 34
3
votes
2 answers

Exception handling in cython

I have two .pyx files - bar.pyx and baz.pyx. I want to combine them into a single .so file. In baz.pyx I have a function baz that should do some checks and raise an exception if something goes wrong. In bar.pyx I want to call baz() and expect…
Tzoiker
  • 1,354
  • 1
  • 14
  • 23
3
votes
0 answers

Accessing a c++ vector/array from python via cython

I am wrapping a c++ program via cython and would like to make a vector from this program available in Python. I have written a getter method for the vector, which works fine except that it returns a copy of the data: # in cython from libcpp.vector…
Samufi
  • 2,465
  • 3
  • 19
  • 43
3
votes
0 answers

Cython error while installing pandas from setup.py

Facing some errors related to cython while installing pandas from setup.py. Unable to fix that error. I'm trying to install the library offline with setup.py [16/40] Cythonizing pandas\_libs/reduction.pyx Error compiling Cython file: …
user13510399
3
votes
1 answer

What is this declaration in Cython? cdef PyObject **workers. Is it a pointer to a pointer?

I'm trying to utilize the concepts in this sample code to run some Cython code in parallel, but I can't seem to find any information in the Cython documentation about what this notation actually means. cdef FLOAT_t[:] numbers cdef unsigned…
stagermane
  • 1,003
  • 2
  • 12
  • 29
3
votes
2 answers

Wrapping C++ classes that contain wxString with Cython

I'm working on a Python extension to tie in with a C++ application written using wxWidgets for the GUI. I'm using Cython, and have the basic system (build tools, plus a starter extension with appropriate version details etc) happily working. I'm…
Blair
  • 15,356
  • 7
  • 46
  • 56
3
votes
0 answers

pyobjus nameerror: name 'build_ext' is not defined during installation

I'm trying to install pyobjus but I still geting error: ERROR: Command errored out with exit status 1: command: /root/anaconda3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lm35sz6r/pyobjus/setup.py'"'"';…
3
votes
1 answer

Reference counting of memoryviews with nogil

I don't quite understand how reference counting is done with memoryviews in large/longer nogil sections. Let's assume basically all my code is nogil, except for the creation of a numpy-array-to-memoryview deep down. The memoryview is returned and…
oli
  • 659
  • 1
  • 6
  • 18
3
votes
1 answer

in Cython

Can s be directly declared for use in Cython constructors? As I understand, this is possible: # Cython cdef int[3] li = [1, 2, 3] # C++ int[3] li = {1, 2, 3} But similar syntax for the std::vector class like cdef vector[int] *…
fhchl
  • 711
  • 8
  • 18
3
votes
1 answer

Cython subclassing "First base of" ... "is not an extension type" even though it is defined with cdef

I am working with Cython to optimize my Python code for a university project. To do that I want to transform python classes into extension types. I currently have issues compiling one extension type which should be a subclass of another extension…
Panda-vid
  • 33
  • 5
3
votes
2 answers

Build Cython and gevent on OSX

When I build gevent, I get an error Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.1/bin/cython", line 7, in from Cython.Compiler.Main import main File…
Jintwo
  • 73
  • 1
  • 5