当前位置:网站首页>Cython的使用
Cython的使用
2022-06-10 06:55:00 【hxxjxw】
cython的python的区别就在于,在cython里你也要对变量指定类型
我们知道python中是不需要对变量指定类型的,程序会自己判断,这也导致了python的运行慢
Python
x = 5C/C++
int x = 5Cython
cdef int x = 5 或 cpdef int x = 5将python代码用cython编译
例如我们现在有python代码hxx_try.py
def hxx_test(x): y = 0 for i in range(x): y += i return y
首先,将hxx_try.py修改后缀名为hxx_try.pyx, 然后新建setup.py
setup.py
from setuptools import setup from Cython.Build import cythonize setup.py( name = 'hxx_learn_cython', ext_modules = cythonize("hxx_try.pyx"), zip_safe = False, )zip_safe=False要带着
然后
python setup.py build_ext --inplace
新生成.c文件,.so文件和build目录
![]()
目录结构是
此时,新建一个python文件
from hxx_try import hxx_test print(hxx_test(10))就可以执行了
实际发挥作用的是hxx_try.cpython-38-x86_64-linux-gnu.so这个文件。将其他文件包括hxx_try.pyx删除,程序仍然可以执行
边栏推荐
- Keyboard events and form events
- P1073 [noip2009 improvement group] optimal trade problem solving hierarchical graph shortest path
- Jerry's aicmd command [chapter]
- Qt--- create dialog 2: quick dialog design
- LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)
- spark 避免对一个列重复解析json
- Tensorflow experiment 10 - image flipping and zooming
- Summary of CUDA parallel computing optimization strategies
- Beyond compare
- 判断进程是否有管理员权限
猜你喜欢

YoseZang 原创 特征码定位器 SignatureTest V6.36 Rls 发布

Read in one second: the practical operation of increasing capital and shares of enterprises!

深度解析智能運維下告警關聯頻繁項集挖掘算法原理

Common string input stream collation (gets (), fgets, getline (), cin get()、cin. getline())

在 Kubernetes 中基于 StatefulSet 部署 MySQL(上)

Embedded development | common operations of EEPROM driver code

TeleyeControlor V8.47版本发布 更改Socket框架

Wechat team sharing: how the wechat background does not crash under massive concurrent requests

Where will the alarm messages go? Fly in the flying book

一举刷新 54 个中文 NLP 任务基准,ERNIE3.0加持下的EasyDL可能是市面上最好用的NLP开发平台...
随机推荐
电脑新加内存条后 游戏崩溃 浏览器卡死 电脑蓝屏
Loj10131. "all in one" 4.4 example 2 "dark chain problem solving tree difference (edge difference)
Problem: interceptor missile
[econometrics] instrumental variable estimation and two-stage least square method
All in one 1258 Dynamic programming of digital pyramid problem solving
TeleyeControlor V8.7 修复广域网上线 增加显示延时功能
LabVIEW控制Arduino实现红外测距(进阶篇—6)
Nextcloud internal server error the server cannot complete your request workaround
Leetcode game 79 biweekly - complete all questions
27. encapsulate an animation function
Solving the problem of interval updating + interval maximum value by block sequence
最长公共子序列
ShardingSphere实践(6)——弹性伸缩
Wechat team sharing: how the wechat background does not crash under massive concurrent requests
Shardingsphere practice (6) - elastic scaling
spark 避免对一个列重复解析json
Read in one second: the practical operation of increasing capital and shares of enterprises!
解析:稳定币不是“稳定的币”,其本质是一种产品
一本通1258.数字金字塔 题解 动态规划
Efficiency improvement: realize personal task management and monitoring with notation




