为了解决C运行时冲突的问题,决定在本地编译使用Visual Studio 2010编译wxPython,话不多说,开始处理。
1、首先下载wxPython-2.8.12.1源码包,下载地址为http://downloads.sourceforge.net/wxpython/wxPython-src-2.8.12.1.tar.bz2;
2、解压源码包至本地,在这里解压到D:\wxPython-2.8.12.1;
3、设置环境变量,以便在后继部分容易执行命令和解释;
set WXDIR=d:\wxPython-2.8.12.1
set WXWIN=%WXDIR%
4、拷贝%WXWIN%\include\wx\msw\setup0.h为%WXWIN%\include\wx\msw\setup.h,编辑其中的宏定义,修改的部分为:
wxUSE_DEBUGREPORT 0
wxUSE_EXCEPTIONS 0
wxUSE_DIALUP_MANAGER 0
wxUSE_GRAPHICS_CONTEXT 1
wxUSE_GLCANVAS 1
wxUSE_POSTSCRIPT 1
wxUSE_DIB_FOR_BITMAP 1
wxUSE_DATEPICKCTRL_GENERIC 1
wxUSE_UNICODE 1
wxUSE_UNICODE_MSLU 1
wxUSE_MEMORY_TRACING 0
wxUSE_DEBUG_CONTEXT 0
5、编辑%WXDIR%\build\msw目录下的makefile.vc,找到如下的内容并修改;
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default"
__NDEBUG_DEFINE_p = /DNDEBUG
!endif
改为
!if "$(BUILD)" == "release" && "$(DEBUG_RUNTIME_LIBS)" == "default" && "$(DEBUG_FLAG)" == "0"
__NDEBUG_DEFINE_p = /DNDEBUG
!endif
6、执行命令开始编译:
cd %WXDIR%\build\msw
nmake -f makefile.vc OFFICIAL_BUILD=1 SHARED=1 MONOLITHIC=0 USE_OPENGL=1 USE_GDIPLUS=1 DEBUG_FLAG=1 CXXFLAGS=/D__NO_VC_CRTDBG__ WXDEBUGFLAG=h BUILD=release UNICODE=1 MSLU=1
7、创建和安装扩展:
cd %WXDIR%\wxPython
python setup.py build_ext --inplace MONOLITHIC=0 UNICODE=1
python setup.py build_ext --inplace MONOLITHIC=0 UNICODE=1 install
8、拷贝其余依赖库:
set PYTHONLIBSITE=%PYTHONDIR%\Lib\site-packages
copy %WXWIN%\lib\vc_dll\wx*h_*.dll %PYTHONLIBSITE%\wx-2.8-msw-unicode\wx
copy wx\lib\myole4ax.idl %PYTHONLIBSITE%\wx-2.8-msw-unicode\wx\lib
copy wx\lib\myole4ax.tlb %PYTHONLIBSITE%\wx-2.8-msw-unicode\wx\lib
copy wxversion\wxversion.py %PYTHONLIBSITE%\
copy wx\*.pyd %PYTHONLIBSITE%\wx-2.8-msw-unicode\wx
9、编写Hello World测试:
import wx
class MyApp(wx.App):
def OnInit(self):
wx.MessageBox("Hello wxPython", "wxApp")
return True
if __name__ == "__main__":
app = MyApp(False)
app.MainLoop()
出现窗口就OK!