create a python code like that
nepyx.py
def test(x):
print(str(x))
To work with cython rename this nepyx.py file to nepyx.pyx extension file.
Now to compile to this .pyx file to c code create an setup.py file like this
setup.py
from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize('nepyx.pyx'),
)
this work on only one file in that directory , but if your directory contains more than one .pyx file then write this , you can also use this file for single file.
from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize('./*.pyx'),
)
This setup.py file should be kept in the directory where is .pyx file.
To compile .pyx run the below command in terminal and it will generate .so compiled binary file in a respected directory and import this .so file
rnjn@rnjn:~/PycharmProjects/cython-project$ python3 setup.py build_ext --inplace
Compiling ./nepyx.pyx because it changed.
[1/1] Cythonizing ./nepyx.pyx
/usr/lib/python3/dist-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/rnjn/PycharmProjects/cython-project/nepyx.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'nepyx' extension
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.8 -c ./nepyx.c -o build/temp.linux-x86_64-3.8/./nepyx.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.8/./nepyx.o -o build/lib.linux-x86_64-3.8/nepyx.cpython-38-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-3.8/nepyx.cpython-38-x86_64-linux-gnu.so ->
rnjn@rnjn:~/PycharmProjects/cython-project$
After compiling this nepyx.cpython-38-x86_64-linux-gnu.so was generated and keep it as usual and can delete your others .py and .pyx file or copy them to other directory to test the how its work. Do not rename this .so file otherwise will not work.
Now create a test file and import this .so file using import nepyx to see how its work:
testing.py
#testing.py
import nepyx
nepyx.test(4)
After running this testing.py file you can see the following output:
rnjn@rnjn:~/PycharmProjects/cython-project$ python3 testing.py
4
rnjn@rnjn:~/PycharmProjects/cython-project$
Comments50
buy cialis 10mg
hair transplant and propecia
xfqfhayt
zwztmcol
rqiewigg
avbagcbp
xrghkxhy
emghbaqc
osxbubdc
pxihfppa
ygvcnucn
nkvsptog
rlggxsgl
efycqubf
ojdbmyie
gblsgkbv
wtkciunk
ujoznjal
lgcferux
acuakjff
lnrcoddy
zbvzgxeh
qqekmiwvxk
nrhbewzh
setxpmcl
ysbmkdgh
cvwxebea
kjkpvciv
dvmuhnkk
zzuivnlt
ddvkhuyrb
rvsaphix
ecdtdwjwz
abhtwcdd
rcechzph
myijxysx
svhnypij
izfyikew
uttiqepd
tjvhoons
nohnrqir
pnugzcutok
pptanzlz
qhtdlrue
inwvraqe
fjsgctze
jjlgrujg
wzddsaiu
ytevonrc
wltmdjbq