Cython
Добавлено: Пн, 12 ноября 2018, 00:09:22
Способ ускорения питона.
Может получиться сделать из него экзешник
https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html
pip install Cython --install-option="--no-cython-compile"
Может получиться сделать из него экзешник
https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html
- Спойлер
- Cython Hello World
As Cython can accept almost any valid python source file, one of the hardest things in getting started is just figuring out how to compile your extension.
So lets start with the canonical python hello world:
print("Hello World")
Save this code in a file named helloworld.pyx. Now we need to create the setup.py, which is like a python Makefile (for more information see Source Files and Compilation). Your setup.py should look like:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("helloworld.pyx")
)
To use this to build your Cython file use the commandline options:
$ python setup.py build_ext --inplace
Which will leave a file in your local directory called helloworld.so in unix or helloworld.pyd in Windows. Now to use this file: start the python interpreter and simply import it as if it was a regular python module:
>>> import helloworld
Hello World
pip install Cython --install-option="--no-cython-compile"