如何无错误构建py2exe?

5 投票
1 回答
3240 浏览
提问于 2025-04-16 17:34

我平时不太用Windows,但我需要把我的Python代码打包成exe文件,所以想用py2exe来实现。我有一台安装了Python 2.6.6的XP系统。我下载了py2exe-0.6.9的源代码,但在尝试安装时(通过“python setup.py install”),出现了一个错误:“找不到vcvarsall.bat”。我在网上搜索,发现了这个帖子,里面有个网友建议安装一个定制版的MinGW GCC二进制文件,可以在这里找到。我按照这个建议做了,但现在在尝试安装py2exe时又出现了新的错误。以下是输出内容:

C:\Documents and Settings\Administrator\Desktop\py2exe-0.6.9>python setup.py install
C:\Documents and Settings\Administrator\Desktop\py2exe-0.6.9\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated
  import sets
running install
running build
running build_py
running build_ext
building '_memimporter' extension
creating build\temp.win32-2.6
creating build\temp.win32-2.6\Release
creating build\temp.win32-2.6\Release\source
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -DPYTHONDLL=\"PYTHON26.DLL\" -DPYTHONCOM=\"pythoncom26.dll\" -IC:\Python26\include -IC:\Python26\PC -c source/MemoryModule.c -o build\temp.win32-2.6\Release\source\memorymodule.o
source/MemoryModule.c:30: warning: ignoring #pragma warning
source/MemoryModule.c: In function 'BuildImportTable':
source/MemoryModule.c:364: warning: pointer targets in passing argument 1 of 'MyLoadLibrary' differ in signedness
source/MemoryModule.c: In function 'GetNameTable':
source/MemoryModule.c:610: warning: passing argument 4 of 'qsort' from incompatible pointer type
source/MemoryModule.c: In function 'MemoryGetProcAddress':
source/MemoryModule.c:637: warning: passing argument 5 of 'bsearch' from incompatible pointer type
c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -DPYTHONDLL=\"PYTHON26.DLL\" -DPYTHONCOM=\"pythoncom26.dll\" -IC:\Python26\include -IC:\Python26\PC -c source/_memimporter_module.c -o build\temp.win32-2.6\Release\source\_memimporter_module.o

In file included from source/_memimporter.c:8,
                 from source/_memimporter_module.c:2:
source/Python-version.h:13: error: redefinition of typedef 'Py_ssize_t'
C:\Python26\include/pyport.h:115: error: previous declaration of 'Py_ssize_t' was here
error: command 'gcc' failed with exit status 1

1 个回答

0

你可以考虑重新打开这个链接中的问题,地址是 http://bugs.python.org/issue1485576,并提供你的测试案例来支持你的观点。

撰写回答