PYTHONL Telegram 4918
Ускорь Python без переписывания — скомпилируй код в .so через Cython

Нужно ускорить медленные куски Python-кода (циклы, численные вычисления, парсинг)?

Не обязательно лезть в C или переписывать всё под NumPy. Можно взять свой .py`-файл, добавить одну строчку и превратить его в бинарный .so`‑модуль через Cython — без изменения логики.



# 1. Устанавливаем Cython и компилятор
pip install cython
sudo apt install build-essential

# 2. Переименовываем файл
mv myscript.py myscript.pyx

# 3. Создаём setup.py
echo '
from setuptools import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize("myscript.pyx"))
' > setup.py

# 4. Компилируем
python3 setup.py build_ext --inplace

# 5. Используем как обычный модуль
python3 -c 'import myscript; myscript.main()'


@pythonl



tgoop.com/pythonl/4918
Create:
Last Update:

Ускорь Python без переписывания — скомпилируй код в .so через Cython

Нужно ускорить медленные куски Python-кода (циклы, численные вычисления, парсинг)?

Не обязательно лезть в C или переписывать всё под NumPy. Можно взять свой .py`-файл, добавить одну строчку и превратить его в бинарный .so`‑модуль через Cython — без изменения логики.



# 1. Устанавливаем Cython и компилятор
pip install cython
sudo apt install build-essential

# 2. Переименовываем файл
mv myscript.py myscript.pyx

# 3. Создаём setup.py
echo '
from setuptools import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize("myscript.pyx"))
' > setup.py

# 4. Компилируем
python3 setup.py build_ext --inplace

# 5. Используем как обычный модуль
python3 -c 'import myscript; myscript.main()'


@pythonl

BY Python/ django


Share with your friend now:
tgoop.com/pythonl/4918

View MORE
Open in Telegram


Telegram News

Date: |

Image: Telegram. The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: Hui said the time period and nature of some offences “overlapped” and thus their prison terms could be served concurrently. The judge ordered Ng to be jailed for a total of six years and six months. Commenting about the court's concerns about the spread of false information related to the elections, Minister Fachin noted Brazil is "facing circumstances that could put Brazil's democracy at risk." During the meeting, the information technology secretary at the TSE, Julio Valente, put forward a list of requests the court believes will disinformation. Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place.
from us


Telegram Python/ django
FROM American