Questions tagged [cimport]

The cimport statement is a statement of Cython that is used in a definition file (*.pxd) or in an implementation file (*.pyx) file in order to access identifiers that are declared in another definition file (*.pxd).

The form of a cimport statement is analogous to Python import statements:

cimport module
cimport package.module
cimport package.module as name

from module cimport name
from module cimport name as other_name
from package cimport module
from package cimport module as other_name
from package.module cimport name
from package.module cimport name as other_name

as well as variants of these forms with commas, for example:

from module import name_1 as other_name_1, name_2, name_3
11 questions
8
votes
1 answer

`cimport` causes error in interactive Python interpreter

Running cimport cython or cimport numpy in the Python interpreter results in the following error: cimport cython File "", line 1 cimport cython ^ SyntaxError: invalid syntax Is it environment variables path…
Oleg
  • 311
  • 2
  • 3
  • 7
7
votes
2 answers

cython: relative cimport beyond main package is not allowed

I am trying to use explicit relative imports in cython. From the release notes it seems like relative imports should work after cython 0.23, and I'm using 0.23.4 with python 3.5. But I get this strange error that I cannot find many references to.…
emschorsch
  • 1,619
  • 3
  • 19
  • 33
4
votes
1 answer

`cimport numpy` raises error using Cython

I am trying to cimport NumPy into a Python 2.7 shell from a .pyx file, but it keeps giving me the same error: I made a .pyx file called numpyx just to see if it was part of the bigger code I was running, the file contains: cimport numpy as np a =…
user991926
  • 101
  • 1
  • 6
4
votes
2 answers

Set setuptools to create cimportable package with headers availible

I try to implement the answer https://stackoverflow.com/a/57480599/7482208, but I am stuck on cimporting one package from another. The code is here: https://github.com/iamishalkin/setuptools_cython_question What I want is to have one independent…
Ivan Mishalkin
  • 1,049
  • 9
  • 25
4
votes
2 answers

Why doesn't my Cython cimport for a pxd file work?

I'm new to Cython, so I might be missing something obvious, but I've read through the documentation and been banging my head against this for a while. I have a *.pyx file that I build using a setup.py file as follows: from distutils.core import…
Eli
  • 36,793
  • 40
  • 144
  • 207
3
votes
1 answer

How do you get cimport to work in Cython?

I have a directory structure as so: /my_module init.py A/ __init__.py a.pyx B/ __init__.py b.pyx In b.pyx I want to cimport functions from A.a. A regular python import works, but a cimport always fails. Also, I'm compiling A/ and B/…
user926983
  • 33
  • 1
  • 4
2
votes
1 answer

Building Python package containing multiple Cython extensions

I have the following directory structure: testcython/ setup.py testcython/ __init__.py foo.pyx stuff.py bar/ __init__.pxd __init__.py bar.pxd bar.pyx where the…
sjrowlinson
  • 3,297
  • 1
  • 18
  • 35
1
vote
1 answer

Cython: cannot get relative cimport to work

I am testing relative imports in Cython to use in my own project, but I can't seem to get it working. I also tried this answer, but still couldn't get it to work. I am using Cython doc's example, but changing the file structure so that it resembles…
0
votes
0 answers

Jupyter notebook SyntaxError: invalid syntax from libc.math cimport sqrt

I tried this at jupyter notebook %load_ext Cython I was able to install cython successfully but I couldn't use cimport %%cython from libc.math cimport sqrt import numpy as np def filt_conv3(double complex[:,:] filterInput, Py_ssize_t…
shi
  • 1
  • 1
0
votes
0 answers

sum and mean function in cython with nogil

I have math_helper.pyx that is written in cython with nogil. I have another cython script named feature.pyx that uses m_mean function, however, its output (z_mean) is always zero. I don't know where the problem is. this is math_helper.pyx cimport…
0
votes
1 answer

Cython- import class to pyx file

For example let's say we have two classe, Bus- Implement The physical bus line. src/bus/bus.pxd cdef class Bus: cdef int get_item(self) src/bus/bus.pxd: cdef class Bus: cdef int get_item(self): return 5 CPU- Implement The…
Guy-Arieli
  • 33
  • 7