|
1 | 1 | # AutoCython |
| 2 | +中文 | [English](https://github.com/EVA-JianJun/AutoCython/blob/master/README.en.md) |
2 | 3 |
|
3 | | -**自动 Cython, 使用 Cython 批量编译 `.py` 文件为 `.pyd` 文件!** |
4 | | -![py_pyd][1] |
| 4 | +**自动 Cython:一键将 Python 文件批量编译为 PYD 文件** |
| 5 | + |
5 | 6 |
|
6 | | -## 安装 |
| 7 | +## ✨ 特性亮点 |
| 8 | +- 单文件/多文件批量编译 |
| 9 | +- 跨平台支持 (Windows/Linux/MacOS) |
| 10 | +- 简洁命令行界面 |
7 | 11 |
|
8 | | - pip install AutoCython-jianjun |
9 | | - |
10 | | -## 依赖 |
11 | | - |
12 | | -[Cython](https://github.com/cython/cython) 和 C/C++ 编译器 |
13 | | - |
14 | | -**如果你都配置完毕了你可以跳过本节.** |
15 | | - |
16 | | -### Cython |
17 | | - |
18 | | -``` |
19 | | -pip install Cython |
| 12 | +## 📦 安装 |
| 13 | +```bash |
| 14 | +pip install AutoCython-jianjun |
20 | 15 | ``` |
21 | 16 |
|
| 17 | +## ⚙️ 依赖环境 |
22 | 18 | ### C/C++ 编译器 |
| 19 | +- **Windows**: Visual Studio |
| 20 | +- **Linux**: gcc & g++ |
23 | 21 |
|
24 | | -推荐 `gcc` 和 `visual studio` 选一个, 其他编译器请查阅 Cython 文档. |
25 | | - |
26 | | -* `VS` 安装简便, 占用空间大, 配置简单. |
27 | | -* `gcc` 安装简便, 占用空间小, 配置比较复杂. |
28 | | - |
29 | | -不想折腾或者你是 Windows 的话推荐安装 VS, Linux 等系统可以直接使用自带的 gcc。 |
30 | | - |
31 | | -大部分的编译环境都可以使用, 我在 Win, Linux, Mac, Python3.6 到 Python3.10 都可以使用. |
32 | | - |
33 | | -**需要注意的是, 如果你使用的 Python 是64位的, 那么对应的 C、C++ 编译器也必须为64位;** |
34 | | - |
35 | | -**win下gcc推荐安装MinGW**: |
36 | | - |
37 | | -* 64位:<http://mingw-w64.org/> |
38 | | -* 32位:<http://www.mingw.org/> |
| 22 | +**重要提示**:编译器架构必须与Python解释器一致(64位Python需64位编译器) |
39 | 23 |
|
40 | | -## 使用 |
| 24 | +> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目 |
41 | 25 |
|
42 | | -![命令行][11] |
| 26 | +## 🚀 使用指南 |
| 27 | +### 命令行操作 |
| 28 | + |
43 | 29 |
|
44 | | -### 命令行 |
| 30 | +```bash |
| 31 | +# 编译单个文件 |
| 32 | +AutoCython -f test.py |
45 | 33 |
|
46 | | -使用命令行进行编译: |
| 34 | +# 编译整个目录 |
| 35 | +AutoCython -p D:/python_code/ProjectPath |
47 | 36 |
|
48 | | -`AutoCython -h` 或者 `AutoCython --ch` 查看英文和中文帮助. |
49 | | - |
50 | | - # 编译一个文件 |
51 | | - AutoCython -f test.py |
52 | | - |
53 | | - # 编译一个目录 |
54 | | - AutoCython -C D:/python_code/ProjectPath |
55 | | - |
56 | | -![AutoCython][2] |
57 | | - |
58 | | -**例子** |
59 | | - |
60 | | -编译目录 `D:/python_code/ProjectPath`\ |
61 | | -排除所有名为 `tmp.py` 的文件\ |
62 | | -排除 `./ProjectPath/print_cy.py` 文件\ |
63 | | -排除 `./ProjectPath/data/tmp` 目录下的文件不编译\ |
64 | | -使用2个CPU核心\ |
65 | | -只删除编译后产生的 `build` 文件夹和中间文件 `setup_file`, 保留自动生成的 `C` 代码.\ |
66 | | - |
67 | | - AutoCython -C D:/python_code/ProjectPath -E tmp.py;./ProjectPath/print_cy.py;./ProjectPath/data/tmp -M 2 -D bp |
68 | | - |
69 | | -## 特性 |
70 | | - |
71 | | -* **全自动**:自动编译当前目录下所有.py文件, 支持指定目录编译或单文件编译; |
72 | | -* **个性化**:支持指定排除目录或排除文件跳过编译; |
73 | | -* **高效率**:默认启动进程数为cpu核心数四分之一, 大多数情况下可以把cpu跑满; |
74 | | -* **易纠错**:快速纠错, 在编译失败时能极快的获取错误信息; |
75 | | - |
76 | | -### 常见错误 |
| 37 | +# 编译后删除源代码 (默认不删除) |
| 38 | +AutoCython -d True -f test.py |
| 39 | +AutoCython -d True -p D:/python_code/ProjectPath |
| 40 | +``` |
77 | 41 |
|
78 | | -* `print(end='')`\ |
79 | | -Cython 不支持 print 函数的 end 参数, 可以在外部定义 `def my_print(*args, **kwargs): print(*args, end='', **kwargs)`, 然后在需要编译的文件中导入这个外部函数. |
| 42 | +### 编译界面 |
| 43 | + |
80 | 44 |
|
81 | | -* `新建文本文档.py`\ |
82 | | -文件名需要符合 `C` 命名规范 |
| 45 | +### 手动排除文件不编译 |
| 46 | +在文件头部 **前两行** 添加声明: |
| 47 | +```python |
| 48 | +# AutoCython No Compile |
| 49 | +# 此文件将跳过编译处理 |
| 50 | +``` |
83 | 51 |
|
84 | | -其他问题请查阅 `Cython` 官方文档. |
| 52 | +## ⚠️ 常见问题解决 |
85 | 53 |
|
86 | | -### 手动指定不编译 |
| 54 | +一般是源代码中有 Cython 不支持的语句, 或者文件名不支持等. |
| 55 | + 可以查阅 [Cython Wiki](https://github.com/cython/cython/wiki) 项目 官方文档, 或者提 Issue. |
87 | 56 |
|
88 | | -在不需要编译的文件 **头两行** 任意一行写上 `# AucoCython No Compile` 则该文件会跳过编译. |
| 57 | +## 📅 更新记录 |
| 58 | +### V2 版本 |
| 59 | +1. 20250609 release V2.0.0 重构了代码, 使用新的界面 |
89 | 60 |
|
90 | | -## 更新记录 |
| 61 | +### V1 版本 |
91 | 62 | 1. 20220613 更新对Linux的支持, Linux下需要配置gcc&g++ |
92 | 63 | 2. 20221123 可以通过文件头手动指定不编译的文件 |
93 | 64 | 3. 20230306 更新可以指定命令行头如 `Python310` 以此支持非Widnows系统下编译 |
94 | 65 | 4. 20230324 更新文档 |
95 | | -5. 20240506 修复编译失败时遗漏复原 \_\_init\_\_.py 的问题 |
96 | | - |
97 | | - [1]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20210824.png |
98 | | - [2]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_2.jpg |
99 | | - [3]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_3.jpg |
100 | | - [4]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_4.jpg |
101 | | - [5]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_5.jpg |
102 | | - [6]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_6.jpg |
103 | | - [7]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_7.jpg |
104 | | - [8]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_8.jpg |
105 | | - [9]: https://github.com/EVA-JianJun/AutoCython/releases |
106 | | - [10]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_10.jpg |
107 | | - [11]: https://raw.githubusercontent.com/EVA-JianJun/GitPigBed/master/blog_files/img/AutoCython_20200316_11.jpg |
| 66 | +5. 20240506 修复编译失败时遗漏复原 \_\_init\_\_.py 的问题 |
0 commit comments