为 Windows 构建 Python C 扩展模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/101061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:15:09  来源:igfitidea点击:

Building Python C extension modules for Windows

pythonwindows

提问by Will Harris

I have a C extension module and it would be nice to distribute built binaries. Setuptools makes it easy to build extensions modules on OS X and GNU/Linux, since those OSs come with GCC, but I don't know how to do it in Windows.

我有一个 C 扩展模块,分发构建的二进制文件会很好。Setuptools 可以轻松地在 OS X 和 GNU/Linux 上构建扩展模块,因为这些操作系统带有 GCC,但我不知道如何在 Windows 中进行。

Would I need to buy a copy of Visual Studio, or does Visual Studio Express work? Can I just use Cygwin or MinGW?

我需要购买 Visual Studio 的副本,还是 Visual Studio Express 可以工作?我可以只使用 Cygwin 或 MinGW 吗?

回答by Thomas Wouters

Setuptools and distutils don't come with gcc, but they use the same compiler Python was built with. The difference is mostly that on the typical UNIX system that compiler is 'gcc' and you have it installed.

Setuptools 和 distutils 不附带 gcc,但它们使用与 Python 构建的相同编译器。不同之处主要在于在典型的 UNIX 系统上,编译器是“gcc”并且您已经安装了它。

In order to compile extension modules on Windows, you need a compiler for Windows. MSVS will do, even the Express version I believe, but it does have to be the same MSVC++ version as Python was built with. Or you can use Cygwin or MinGW; See the appropriate section of Installing Python Modules.

为了在 Windows 上编译扩展模块,您需要一个适用于 Windows 的编译器。MSVS 可以,即使是我相信的 Express 版本,但它必须与构建 Python 的 MSVC++ 版本相同。或者你可以使用 Cygwin 或 MinGW;请参阅安装 Python 模块的相应部分。