Python3 编译 .py 为 .so .pyd
发表于 : | 「CC BY-NC-SA 4.0」 | 阅读 : 1868

Windows 里面的 .pyd 是类似 .so .dll 动态链接库的一种 Python 文件

) 软件和环境

  1. Win10 x64
  2. Python 3.8.10 x86
  3. Cython
  4. py2sec.py
  5. VS_2019_Community

) 安装 Python 3.8.10 x86

Python 3.8.10 32位 点击下载

其它 Python 版本 点击查看

注意:我现在只用到的是 32位 , 所以下载32位 的版本, 当然 最后编译出来的 .pyd 也是32位的

) 安装 Cython

pip install cython

) 下载 py2sec

点击 到 github 下载

我的备份下载(可能不是最新)

python py2sec.py -f test.py -r
# 生成 test.pyd 之后 模块名为 test 不能改名, 调用时,有错误弹出, 编译之前改好 test.py 的名称

) 安装 VS_2019_Community

不安装VS可以开始编译, 但会出现 “Unable to find vcvarsall.bat”

去下载 Visual Studio 2019 Community

* 如果页面发生改变, 请找到 VS 2019 Community 下载

) 安装完成后重启

TOP