Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cython does not work
#1
cannot display Hello on cython

file: set.py
from distutils.core import setup
from Cython.Build import cythonize
import temp

compiler_directives = {
    'language_level': 2,
    'optimize.use_switch': True,
    'profile': True,
}

setup(
    packages=["XXXXXX"],
    ext_modules=cythonize("temp.pyx",
       # module_list="temp.pxd", #pyx
        #compiler_directives=compiler_directives,
    )
)
file temp.pyx
cdef class Temp1:
                
                cdef void as(self):
                                print("Hello")
Temp1.as()
Reply
#2
as is a keyword in python. This may be the cause of the error. Can't you rename the method?
Reply
#3
fixed as on pprr

file: set.py
from distutils.core import setup
from Cython.Build import cythonize
import temp

print("y")

compiler_directives = {
    'language_level': 2,
    'optimize.use_switch': True,
    'profile': True,
}
 
setup(
    packages=["XXXXXX"],
    ext_modules=cythonize("temp.pyx",
       # module_list="temp.pxd", #pyx
        #compiler_directives=compiler_directives,
    )
)
file temp.pyx
from time import *
#cimport ctemp

cdef class Temp1:
                
                cdef void pprr(self):
                                print("rr")

cdef Temp1 p1
p1=Temp1()
p1.pprr()
print("Hello World")
after starting set.py the program outputs the following---------------------------------------------------------------
Output:
=========== RESTART: I:\Питон\ПРОГРАМЫ PYTHON\Новая папка\setup.py =========== Hello World y Compiling temp.pyx because it changed. [1/1] Cythonizing temp.pyx >>>
It is not clear why does not display print("rr") --------------------------------------------------------
Reply
#4
Normally you don't import the module in 'setup.py'. Removing the 'import temp', here is my output in a linux terminal
Output:
λ python setup.py build_ext --inplace Compiling temp.pyx because it changed. [1/1] Cythonizing temp.pyx running build_ext building 'temp' extension creating build creating build/temp.linux-x86_64-2.7 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c temp.c -o build/temp.linux-x86_64-2.7/temp.o x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/temp.o -o /home/eric/Projets/Scratch/2018-12/cytruc/temp.so λ ls build setup.py temp.c temp.pyx temp.so λ python -c "import temp" rr Hello World
Reply
#5
this command starts python temp.pyx build_ext --inplace
starting from the console results in the following
Output:
Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> temp.pyx AttributeError: module 'temp' has no attribute 'pyx'
Reply
#6
once no more answers, I will try to make himself
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cython, Pandas, and Chained Assignment sawtooth500 4 230 Apr-13-2024, 04:18 AM
Last Post: sawtooth500
  I need to add data types to cython conversion python to c Good_AI_User 1 1,008 Aug-19-2022, 07:52 AM
Last Post: Gribouillis
  unable to load an image with C (Cython) HLD202 0 1,310 Jan-13-2022, 09:16 PM
Last Post: HLD202
  Cython np.where slows down the code Johanoosterwaal 1 1,728 Sep-01-2021, 07:33 AM
Last Post: Johanoosterwaal
  How can I use Cython to protect my Python Code? TurboC 2 4,141 Dec-03-2020, 10:37 AM
Last Post: padma121
  Why does Cython generates bad code for Gentoo? AlekseyPython 1 1,850 Dec-26-2019, 01:57 PM
Last Post: AlekseyPython
  How I can speed up my Cython module? AlekseyPython 0 1,705 Oct-26-2019, 01:23 PM
Last Post: AlekseyPython
  Error in compiling cython extension on Python 3.6.4 on Windows 8 goldenmean 3 5,774 Jun-05-2019, 09:37 PM
Last Post: Larz60+
  Help with building Cython modules. jarrod0987 2 3,318 Nov-15-2018, 03:57 AM
Last Post: Larz60+
  Help with Cython in Win 10 jarrod0987 0 3,017 Oct-06-2018, 12:16 PM
Last Post: jarrod0987

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020