from functools import partial
HOSTS = 3
def primes_python(nb_primes):
p = []
n = 2
while len(p) < nb_primes:
# Is n prime?
for i in p:
if n % i == 0:
break
# If no break occurred in the loop
else:
p.append(n)
n += 1
return p
import cythoncython.declare(HOSTS=cython.int)
@cython.locals(p=cython.list, n=cython.int, i=cython.int)
cpdef list primes_python(int nb_primes)
from setuptools import setup, Extension
from Cython.Build import cythonize
prime_extension = Extension('primes_py', sources=['primes_py.py'], depends=['primes_py.pxd'])
setup(
ext_modules=cythonize(['helloworld.pyx', 'primes_cy.py', prime_extension], language_level='3', annotate=True)
)
cdef HOSTS
cdef int HOSTS
HOSTS = cython.declare(cython.int)
"cython.declare()" can be used in Cython modules, not in .pxd files. I
guess that could be clearer in the docs (PR welcome).
These should work. Don't they? What error do you get?
cdef int HOSTS
from primes_py import HOSTS
print(HOSTS)
Traceback (most recent call last):
File "C:/Users/rolla/.PyCharm2019.2/config/scratches/scratch.py", line 1, in <module>
from primes_py import HOSTS
ImportError: cannot import name 'HOSTS' from 'primes_py' (D:\projets\python\cythoniser\primes_py.cp37-win32.pyd)When I declarecdef int HOSTS
in a primes_py.pxd file, I expect that in another python module, I can do thisfrom primes_py import HOSTS
print(HOSTS)but I have this error:Traceback (most recent call last):
File "C:/Users/rolla/.PyCharm2019.2/config/scratches/scratch.py", line 1, in <module>
from primes_py import HOSTS
ImportError: cannot import name 'HOSTS' from 'primes_py' (D:\projets\python\cythoniser\primes_py.cp37-win32.pyd)What do you think I'm doing wrong?
--Best regards.
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/00ef89aa-8051-485e-b6e5-eed9f8592f51%40googlegroups.com.
On Mon, Aug 19, 2019 at 9:36 AM Kevin Tewouda <lewo...@gmail.com> wrote:
When I declarecdef int HOSTS
in a primes_py.pxd file, I expect that in another python module, I can do thisfrom primes_py import HOSTS
print(HOSTS)but I have this error:Traceback (most recent call last):
File "C:/Users/rolla/.PyCharm2019.2/config/scratches/scratch.py", line 1, in <module>
from primes_py import HOSTS
ImportError: cannot import name 'HOSTS' from 'primes_py' (D:\projets\python\cythoniser\primes_py.cp37-win32.pyd)What do you think I'm doing wrong?the pxd file is used to tell *cython* what type the variable is. you still need to create the varibale (name) in primes.py:HOSTS = 45 # or whatever value-CHB
--Best regards.
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/00ef89aa-8051-485e-b6e5-eed9f8592f51%40googlegroups.com.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/CALGmxELi8D7OBATueZg93DELyTLgC_jYS8asFa0j3ewE1Fw6Jg%40mail.gmail.com.
Hi Chris,If you read my first message, this is already what I've done.Best regards.
Le lun. 19 août 2019 à 23:02, 'Chris Barker' via cython-users <cython...@googlegroups.com> a écrit :
On Mon, Aug 19, 2019 at 9:36 AM Kevin Tewouda <lewo...@gmail.com> wrote:
When I declarecdef int HOSTS
in a primes_py.pxd file, I expect that in another python module, I can do thisfrom primes_py import HOSTS
print(HOSTS)but I have this error:Traceback (most recent call last):
File "C:/Users/rolla/.PyCharm2019.2/config/scratches/scratch.py", line 1, in <module>
from primes_py import HOSTS
ImportError: cannot import name 'HOSTS' from 'primes_py' (D:\projets\python\cythoniser\primes_py.cp37-win32.pyd)What do you think I'm doing wrong?the pxd file is used to tell *cython* what type the variable is. you still need to create the varibale (name) in primes.py:HOSTS = 45 # or whatever value-CHB
--Best regards.
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/00ef89aa-8051-485e-b6e5-eed9f8592f51%40googlegroups.com.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris....@noaa.gov
--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/CALGmxELi8D7OBATueZg93DELyTLgC_jYS8asFa0j3ewE1Fw6Jg%40mail.gmail.com.
Hello everyone,can somebody helps me to fix my issue related to variable export? As a reminder I define a variable in the.py file and its declaration in the.pxd file, you can read the first exchanges.