在wsl中使用cython.txt

news2026/5/7 6:53:12
Cython 的本质可以总结如下Cython 是包含 C 数据类型的 Python。Cython 是 Python几乎所有 Python 代码都是合法的 Cython 代码。 存在一些限制但是差不多也可以。 Cython 的编译器会转化 Python 代码为 C 代码这些 C 代码均可以调用 Python/C 的 API。要使用cython, 先要配置c编译器在windows中配置比较麻烦所以在wsl中使用gcc容器。下载安装cythonC:\Users\lt\AppData\Local\Programs\Python\Python313wsl rootDESKTOP-59T6U68:/mnt/c/Users/lt/AppData/Local/Programs/Python/Python313# docker start gcc gcc rootDESKTOP-59T6U68:/mnt/c/Users/lt/AppData/Local/Programs/Python/Python313# docker exec -it gcc bash root6ae32a5ffcde:/# cd /par root6ae32a5ffcde:/par# python3 pip.pyz download cython -d 313 Looking in indexes: https://mirrors.aliyun.com/pypi/simple Collecting cython Downloading https://mirrors.aliyun.com/pypi/packages/ac/25/58893afd4ef45f79e3d4db82742fa4ff874b936d67a83c92939053920ccd/cython-3.2.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (3.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 18.7 MB/s eta 0:00:00 Saved ./313/cython-3.2.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl Successfully downloaded cython root6ae32a5ffcde:/par# python3 pip.pyz install cython -f 313 --no-index --break-system-packages Looking in links: 313 Processing ./313/cython-3.2.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl Installing collected packages: cython Successfully installed cython-3.2.4 WARNING: Running pip as the root user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.编写源代码和setup.py按照旧版文档 https://moonlet.gitbooks.io/cython-document-zh_cn/content/ch1-basic_tutorial.html的说明编写helloworld.pyxprint(Hello World)setup.pyfromdistutils.coreimportsetupfromCython.Buildimportcythonize setup(ext_modulescythonize(helloworld.pyx))编译扩展root6ae32a5ffcde:/par# python3 setup.py build_ext --inplace /par/setup.py:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives from distutils.core import setup Compiling helloworld.pyx because it changed. [1/1] Cythonizing helloworld.pyx running build_ext building helloworld extension creating build creating build/temp.linux-x86_64-3.11 x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werrorformat-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werrorformat-security -Wdate-time -D_FORTIFY_SOURCE2 -fPIC -I/usr/include/python3.11 -c helloworld.c -o build/temp.linux-x86_64-3.11/helloworld.o helloworld.c:31:10: fatal error: Python.h: No such file or directory 31 | #include Python.h | ^~~~~~~~~~ compilation terminated. error: command /usr/local/bin/x86_64-linux-gnu-gcc failed with exit code 1 root6ae32a5ffcde:/par# apt install python-dev Reading package lists... Done Building dependency tree... Done Reading state information... Done Package python-dev is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: python-dev-is-python3 N: Ignoring file debian.sources_org in directory /etc/apt/sources.list.d/ as it has an invalid filename extension E: Package python-dev has no installation candidate root6ae32a5ffcde:/par# apt install python3-dev Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libjs-jquery libjs-sphinxdoc libjs-underscore libpython3-dev libpython3.11 libpython3.11-dev python3.11-dev The following NEW packages will be installed: libjs-jquery libjs-sphinxdoc libjs-underscore libpython3-dev libpython3.11 libpython3.11-dev python3-dev python3.11-dev 0 upgraded, 8 newly installed, 0 to remove and 117 not upgraded. Need to get 7952 kB of archives. After this operation, 36.3 MB of additional disk space will be used. N: Ignoring file debian.sources_org in directory /etc/apt/sources.list.d/ as it has an invalid filename extension Do you want to continue? [Y/n] Get:1 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libjs-jquery all 3.6.1dfsg~3.5.14-1 [326 kB] Get:2 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libjs-underscore all 1.13.4~dfsg~1.11.4-3 [116 kB] Get:3 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libjs-sphinxdoc all 5.3.0-4 [130 kB] Get:4 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libpython3.11 amd64 3.11.2-6deb12u6 [1987 kB] Get:5 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libpython3.11-dev amd64 3.11.2-6deb12u6 [4742 kB] Get:6 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libpython3-dev amd64 3.11.2-1b1 [9572 B] Get:7 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 python3.11-dev amd64 3.11.2-6deb12u6 [615 kB] Get:8 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 python3-dev amd64 3.11.2-1b1 [26.2 kB] Fetched 7952 kB in 1s (8753 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package libjs-jquery. (Reading database ... 64928 files and directories currently installed.) Preparing to unpack .../0-libjs-jquery_3.6.1dfsg~3.5.14-1_all.deb ... Unpacking libjs-jquery (3.6.1dfsg~3.5.14-1) ... Selecting previously unselected package libjs-underscore. Preparing to unpack .../1-libjs-underscore_1.13.4~dfsg~1.11.4-3_all.deb ... Unpacking libjs-underscore (1.13.4~dfsg~1.11.4-3) ... Selecting previously unselected package libjs-sphinxdoc. Preparing to unpack .../2-libjs-sphinxdoc_5.3.0-4_all.deb ... Unpacking libjs-sphinxdoc (5.3.0-4) ... Selecting previously unselected package libpython3.11:amd64. Preparing to unpack .../3-libpython3.11_3.11.2-6deb12u6_amd64.deb ... Unpacking libpython3.11:amd64 (3.11.2-6deb12u6) ... Selecting previously unselected package libpython3.11-dev:amd64. Preparing to unpack .../4-libpython3.11-dev_3.11.2-6deb12u6_amd64.deb ... Unpacking libpython3.11-dev:amd64 (3.11.2-6deb12u6) ... Selecting previously unselected package libpython3-dev:amd64. Preparing to unpack .../5-libpython3-dev_3.11.2-1b1_amd64.deb ... Unpacking libpython3-dev:amd64 (3.11.2-1b1) ... Selecting previously unselected package python3.11-dev. Preparing to unpack .../6-python3.11-dev_3.11.2-6deb12u6_amd64.deb ... Unpacking python3.11-dev (3.11.2-6deb12u6) ... Selecting previously unselected package python3-dev. Preparing to unpack .../7-python3-dev_3.11.2-1b1_amd64.deb ... Unpacking python3-dev (3.11.2-1b1) ... Setting up libpython3.11:amd64 (3.11.2-6deb12u6) ... Setting up libpython3.11-dev:amd64 (3.11.2-6deb12u6) ... Setting up libjs-jquery (3.6.1dfsg~3.5.14-1) ... Setting up libjs-underscore (1.13.4~dfsg~1.11.4-3) ... Setting up libpython3-dev:amd64 (3.11.2-1b1) ... Setting up python3.11-dev (3.11.2-6deb12u6) ... Setting up libjs-sphinxdoc (5.3.0-4) ... Setting up python3-dev (3.11.2-1b1) ... Processing triggers for libc-bin (2.36-9deb12u13) ...编译出错了在网上查到需要安装python-dev实际上对于python3要安装python3-dev再次编译当前目录下生成一个helloworld.c和helloworld.cpython-311-x86_64-linux-gnu.so文件。root6ae32a5ffcde:/par# python3 setup.py build_ext --inplace /par/setup.py:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives from distutils.core import setup running build_ext building helloworld extension x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werrorformat-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werrorformat-security -Wdate-time -D_FORTIFY_SOURCE2 -fPIC -I/usr/include/python3.11 -c helloworld.c -o build/temp.linux-x86_64-3.11/helloworld.o x86_64-linux-gnu-gcc -shared -Wl,-O1 -Wl,-Bsymbolic-functions -g -fwrapv -O2 -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werrorformat-security -Wdate-time -D_FORTIFY_SOURCE2 build/temp.linux-x86_64-3.11/helloworld.o -o /par/helloworld.cpython-311-x86_64-linux-gnu.so root6ae32a5ffcde:/par# python3 Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux Type help, copyright, credits or license for more information. import helloworld Hello World 在python中import 就执行了。再按照新版文档 https://cython.readthedocs.io/en/stable/src/tutorial/cython_tutorial.html#fibonacci-fun 的说明建立fibonacci.pyxdeffib(n):Print the Fibonacci series up to n.a,b0,1whilebn:print(b,end )a,bb,abprint()setup1.pyfromsetuptoolsimportsetupfromCython.Buildimportcythonize setup(ext_modulescythonize(fibonacci.pyx),)编译插件root6ae32a5ffcde:/par# python3 setup1.py build_ext --inplace Traceback (most recent call last): File /par/setup1.py, line 1, in module from setuptools import setup ModuleNotFoundError: No module named setuptools root6ae32a5ffcde:/par# pip download setuptools -d 313 bash: pip: command not found root6ae32a5ffcde:/par# python3 pip.pyz download setuptools -d 313 Looking in indexes: https://mirrors.aliyun.com/pypi/simple Collecting setuptools Downloading https://mirrors.aliyun.com/pypi/packages/9d/76/f789f7a86709c6b087c5a2f52f911838cad707cc613162401badc665acfe/setuptools-82.0.1-py3-none-any.whl (1.0 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 1.8 MB/s eta 0:00:00 Saved ./313/setuptools-82.0.1-py3-none-any.whl Successfully downloaded setuptools root6ae32a5ffcde:/par# python3 pip.pyz install setuptools -f 313 --no-index --break-system-packages Looking in links: 313 Processing ./313/setuptools-82.0.1-py3-none-any.whl Installing collected packages: setuptools Successfully installed setuptools-82.0.1 WARNING: Running pip as the root user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning. root6ae32a5ffcde:/par# python3 setup1.py build_ext --inplace Compiling fibonacci.pyx because it changed. [1/1] Cythonizing fibonacci.pyx running build_ext building fibonacci extension creating build/temp.linux-x86_64-cpython-311 x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werrorformat-security -g -fwrapv -O2 -fPIC -I/usr/include/python3.11 -c fibonacci.c -o build/temp.linux-x86_64-cpython-311/fibonacci.o creating build/lib.linux-x86_64-cpython-311 x86_64-linux-gnu-gcc -shared -Wl,-O1 -Wl,-Bsymbolic-functions -g -fwrapv -O2 build/temp.linux-x86_64-cpython-311/fibonacci.o -L/usr/lib/x86_64-linux-gnu -o build/lib.linux-x86_64-cpython-311/fibonacci.cpython-311-x86_64-linux-gnu.so copying build/lib.linux-x86_64-cpython-311/fibonacci.cpython-311-x86_64-linux-gnu.so -新版的文档用到的setuptools模块需要安装安装后就可以编译成功了。import fibonacci是建立fib函数然后用fibonacci.fib()调用就可以了。root6ae32a5ffcde:/par# python3 Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux Type help, copyright, credits or license for more information. import fibonacci fibonacci.fib(2000) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597再用一个计算质数的程序来比较cython和python的效率编译的so大约比原始py文件快了20%。root6ae32a5ffcde:/par# python3 setup2.py build_ext --inplace Compiling primes.py because it changed. [1/1] Cythonizing primes.py warning: primes.py:75:29: Item lookup of unicode character codes now always converts to a Unicode string. Use an explicit C integer cast to get back the previous integer lookup behaviour. warning: primes.py:76:32: Item lookup of unicode character codes now always converts to a Unicode string. Use an explicit C integer cast to get back the previous integer lookup behaviour. running build_ext building primes extension x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werrorformat-security -g -fwrapv -O2 -fPIC -I/usr/include/python3.11 -c primes.c -o build/temp.linux-x86_64-cpython-311/primes.o x86_64-linux-gnu-gcc -shared -Wl,-O1 -Wl,-Bsymbolic-functions -g -fwrapv -O2 build/temp.linux-x86_64-cpython-311/primes.o -L/usr/lib/x86_64-linux-gnu -o build/lib.linux-x86_64-cpython-311/primes.cpython-311-x86_64-linux-gnu.so copying build/lib.linux-x86_64-cpython-311/primes.cpython-311-x86_64-linux-gnu.so - root6ae32a5ffcde:/par# python3 Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux Type help, copyright, credits or license for more information. import primes root6ae32a5ffcde:/par# time python3 -c import primes real 0m1.846s user 0m1.687s sys 0m0.199s mv primes.cpython-311-x86_64-linux-gnu.so primes.cpython-311-x86_64-linux-gnu.so.old root6ae32a5ffcde:/par# time python3 -c import primes real 0m2.271s user 0m2.074s sys 0m0.222s

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2590683.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…