第一个Cython程序-helloworld

Cython是Python的一个模块,可以将python语言"翻译"成C语言。

如何安装?

bash 复制代码
python -m pip install Cython -i  https://pypi.tuna.tsinghua.edu.cn/simple/ 

新建两个文件helloworld.pyx和setup.py

helloworld.pyx

pyhotn 复制代码
print("hello world")

setup.py

python 复制代码
from setuptools import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

执行bash命令

bash 复制代码
python setup.py build_ext --inplace

将会生成helloworld.c。

输入python进入python解释器,像导入库一样调用上面编写的代码。输入import helloworld.

相关推荐
倔强青铜三2 分钟前
苦练Python第22天:11个必学的列表方法
人工智能·python·面试
倔强青铜三5 分钟前
苦练Python第21天:列表创建、访问与修改三板斧
人工智能·python·面试
Pi_Qiu_1 小时前
Python初学者笔记第十三期 -- (常用内置函数)
java·笔记·python
永远孤独的菜鸟2 小时前
# 全国职业院校技能大赛中职组“网络建设与运维“赛项项目方案
python
mit6.8242 小时前
[Meetily后端框架] 多模型-Pydantic AI 代理-统一抽象 | SQLite管理
c++·人工智能·后端·python
一眼万里*e2 小时前
Python 字典 (Dictionary) 详解
前端·数据库·python
mortimer3 小时前
Python 正则替换陷阱:`\1` 为何变成了 `\x01`?
python·正则表达式
aerror3 小时前
静态补丁脚本 - 修改 libtolua.so
开发语言·python
Dxy12393102164 小时前
Python Docker SDK库详解:从入门到实战
开发语言·python
Blossom.1184 小时前
从“炼丹”到“流水线”——如何用Prompt Engineering把LLM微调成本打下来?
人工智能·python·深度学习·神经网络·学习·机器学习·prompt