简体   繁体   English

使用Cygwin在Windows上编译Python扩展

[英]Compiling Python Extension On Windows With Cygwin

I have been having a terrible time trying to compile a python extension - hopefully someone can help. 我在尝试编译python扩展时经历了一段糟糕的时光-希望有人可以提供帮助。

I initially tried executing 'python.exe setup.py build' but received the error: 'Python was built Visual Studio 2003; 我最初尝试执行“ python.exe setup.py build”,但收到错误:“ Python是Visual Studio 2003内置的; extensions must be built with a compiler that can generate compatible binaries...". 必须使用可以生成兼容二进制文件的编译器来构建扩展。”。

So I then downloaded Cygwin, and have tried sending the switch '-c mingw32'. 因此,我然后下载了Cygwin,并尝试发送开关'-c mingw32'。 A few lines were written into the console - then I get the error message: command 'gcc' failed: Permission denied. 在控制台中写了几行-然后我收到错误消息:命令'gcc'失败:权限被拒绝。

I was initially using the Visual Studio 2010 Command Line to do this, but tried with bash and got the same result. 我最初使用Visual Studio 2010命令行执行此操作,但是尝试使用bash并获得了相同的结果。

I have spent a considerable amount of time researching the issue, and it appears Cygwin uses symlinks for gcc and g++, and windows doesn't understand how to handle this. 我花了大量时间研究这个问题,看来Cygwin在gcc和g ++中使用了符号链接,而Windows无法理解该问题。

How exactly can I force setup.py to use gcc-3.exe instead of the gcc.exe symlink? 我究竟如何强制setup.py使用gcc-3.exe而不是gcc.exe符号链接?

I know it's inelegant, but you can rename the symlink and copy gcc-3.exe to gcc.exe. 我知道这很不雅致,但是您可以重命名符号链接并将gcc-3.exe复制到gcc.exe。 That worked for me when I used Cygwin's gcc. 当我使用Cygwin的gcc时,这对我有用。 You might want to switch to the mingw64-i686 (or mingw64-x86_64) package to get gcc 4.5.3, or just install MinGW-w64 separately for compiling under Windows. 您可能需要切换到mingw64-i686(或mingw64-x86_64)软件包以获取gcc 4.5.3,或者仅安装MinGW-w64即可在Windows下编译。

Also, you can permanently configure distuilts in PythonXX\\Lib\\distutils\\distutils.cfg: 另外,您可以在PythonXX \\ Lib \\ distutils \\ distutils.cfg中永久配置内容:

[build]
compiler = mingw32

[build_ext]
compiler = mingw32

[build_clib]
compiler = mingw32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM