第一个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.

相关推荐
硅基茶水间7 分钟前
「轻量级AI编程桌面软件」代码上下文一键搞定|已开源
python
Hockor36 分钟前
写给前端的 Python 教程三(字符串驻留和小整数池)
前端·后端·python
网安小张39 分钟前
解锁FastAPI与MongoDB聚合管道的性能奥秘
数据库·python·django
GeekAGI40 分钟前
Python 定时器框架
python
KENYCHEN奉孝1 小时前
Pandas和Django的示例Demo
python·django·pandas
拾零吖1 小时前
《Pytorch深度学习实践》ch8-多分类
人工智能·pytorch·python
亿牛云爬虫专家1 小时前
NLP驱动网页数据分类与抽取实战
python·分类·爬虫代理·电商·代理ip·网页数据·www.goofish.com
weixin_466485111 小时前
PyCharm中运行.py脚本程序
ide·python·pycharm
Jay_272 小时前
python项目如何创建docker环境
开发语言·python·docker
老胖闲聊2 小时前
Python Django完整教程与代码示例
数据库·python·django