【发布时间】:2010-03-10 20:26:10
【问题描述】:
我为 Python 编译了一个简单的 hello world C 模块,它在我尝试过的所有东西中都能正常工作,但 IDLE 除外。这是我输入的内容来测试它:
>>> import hello
>>> hello.say_hello('Justin')
我已经从命令提示符(我使用的是 Windows)、Eclipse 的 PyDev 和 PieDream 中使用 Python 进行了尝试,它们都打印出 Hello Justin!。然而,在 IDLE 中它不打印任何东西——它只是给了我提示。
我使用的模块和setup.py来自this page。我认为问题出在编译器上。我正在使用 MinGW,它在 .cfg 文件中设置为 distutils 的编译器。我从命令提示符构建模块:
python setup.py build
得到
running build
running build_ext
building 'hello' extension
creating build
creating build\temp.win32-2.6
creating build\temp.win32-2.6\Release
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include -IC:\Python26\PC -c hellomodule.c -o build\temp.win32-2.6\Release\hellomodule.o
writing build\temp.win32-2.6\Release\hello.def
creating build\lib.win32-2.6
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.6\Release\hellomodule.o build\temp.win32-2.6\Release\hello.def -LC:\Python26\libs -LC:Python26\PCbuild -lpython26 -lmsvcr90 -o build\lib.win32-2.6\hello.pyd
我认为这可能与其中的 -mno-cygwin 部分有关,但我不确定。
关于为什么这个模块不能在 IDLE 中工作的任何想法或建议?我应该使用不同的编译器吗?
【问题讨论】:
-
这只是一个猜测,但您不应该在 Windows 中为 Python 使用 MSVC++ 吗?
-
@javier 您应该能够使用几乎任何 c 编译器。作为旁注,我在 linux 中使用 gcc 进行了教程,并且 idle 做了同样的事情:没有输出,但是 cmd 行有效,等等。好吧,我只是注意到这一点:如果你从命令行运行 idle 并运行脚本,输出被转储到终端窗口中。
-
@Javier 我也尝试过使用 distutils 和 MSVC++ 并得到相同的结果。
标签: python c windows module mingw