]>
Commit | Line | Data |
---|---|---|
1 | Building wxPython on Win32 | |
2 | -------------------------- | |
3 | ||
4 | ||
5 | Building wxPython for use on win32 systems is a fairly simple process | |
6 | consisting of just a few steps. However depending on where you get | |
7 | your sources from and what your desired end result is, there are | |
8 | several permutations of those steps. At a high level the basic steps | |
9 | are: | |
10 | ||
11 | 1. Get the wxWindows sources | |
12 | 2. Build the wxWindows DLL | |
13 | 3. Get the wxPython sources | |
14 | 4. Build and Install wxPython | |
15 | ||
16 | We'll go into more detail of each of these steps below, but first a | |
17 | few bits of background information on tools. | |
18 | ||
19 | I use a tool called SWIG (http://www.swig.org) to help generate the | |
20 | C++ sources used in the wxPython extension module. However you don't | |
21 | need to have SWIG unless you want to modify the *.i files. If you do | |
22 | you'll want to have version 1.1-883 of SWIG and you'll need to apply | |
23 | the patches and updates in wxPython/SWIG and rebuild it. Then you'll | |
24 | need to change a flag in the setup.py script as described below so the | |
25 | wxPython build process will use SWIG if needed. | |
26 | ||
27 | I use the new Python Distutils tool to build wxPython. It is included | |
28 | with Python 2.0, but if you want to use Python 1.5.2 or 1.6 then | |
29 | you'll need to download and install Distutils 1.0 from | |
30 | http://www.python.org/sigs/distutils-sig/ | |
31 | ||
32 | I use Microsoft Visual C++ 6.0 (5.0 with the service packs should work | |
33 | also) to compile the wxPython C++ sources. Since I am using Distutils | |
34 | it should be easier now to build with other win32 compilers such as | |
35 | the free mingw32 or Borland compilers, but I havn't tried them yet. | |
36 | If anybody wants to try it I'll take any required patches for the | |
37 | setup script and for these instructions. | |
38 | ||
39 | And now on to the fun stuff... | |
40 | ||
41 | ||
42 | ||
43 | 1. Get the wxWindows sources | |
44 | ---------------------------- | |
45 | ||
46 | A. There are a few possible ways to get sources for wxWindows. You | |
47 | can download a released version from http://wxwindows.org/ or you | |
48 | can get current development sources from the CVS server. (Some | |
49 | information about annonymous CVS access is at | |
50 | http://wxwindows.org/cvs.htm.) The advantage of using CVS is that | |
51 | you can easily update as soon as the developers check in new | |
52 | sources or fixes. The advantage of using a released version is | |
53 | that it usually has had more testing done. You can decide which | |
54 | method is best for you. | |
55 | ||
56 | B. You'll usually want to use wxWindows sources that have the same | |
57 | version number as the wxPython sources you are using. (Another | |
58 | advantage of using CVS is that you'll get both at the same time.) | |
59 | ||
60 | C. Once you get the sources be sure to put them in a path without a | |
61 | space in it (i.e., NOT c:\Program Files\wx) and set an environment | |
62 | variable named WXWIN to this directory. For example: | |
63 | ||
64 | mkdir \wx2 | |
65 | cd \wx2 | |
66 | unzip wxMSW-2.2.2.zip | |
67 | set WXWIN=c:\wx2 | |
68 | ||
69 | You'll probably want to add that last line to your autoexec.bat or | |
70 | System Properties depending on the type of system you are on. | |
71 | ||
72 | D. Change to the wx2\include\wx\msw directory and copy setup0.h to | |
73 | setup.h and then edit setup.h. This is how you control which parts | |
74 | of wxWindows are compiled into or left out of the build, simply by | |
75 | turning options on or off. I have the following differences from | |
76 | the default setup0.h in my setup.h, but you can experiment with | |
77 | other settings if you like: | |
78 | ||
79 | wxDIALOG_UNIT_COMPATIBILITY 0 | |
80 | wxUSE_GLOBAL_MEMORY_OPERATORS 0 | |
81 | wxUSE_DEBUG_NEW_ALWAYS 0 | |
82 | wxUSE_CMDLINE_PARSER 0 | |
83 | wxUSE_DIALUP_MANAGER 0 | |
84 | wxUSE_DYNAMIC_LOADER 0 | |
85 | wxUSE_TREELAYOUT 0 | |
86 | wxUSE_POSTSCRIPT 1 | |
87 | ||
88 | ||
89 | ** NEW ** | |
90 | Be sure that wxUSE_GLCANVAS is defined to be 0 as wxPython now | |
91 | keeps its own copy of the glcanvas sources and expects that it is | |
92 | not in the main library. This is done to reduce the number of | |
93 | dependant DLLs on the core library and therefore help reduce | |
94 | startup time. | |
95 | ||
96 | ||
97 | ||
98 | 2. Build the wxWindows DLL | |
99 | --------------------------- | |
100 | ||
101 | A. Although MSVC project files are provided I always use the makefiles | |
102 | to build wxWindows because by default the flags are compatible with | |
103 | Python, (and I make sure they stay that way.) You would have to | |
104 | edit the project files a bit to make it work otherwise. | |
105 | ||
106 | B. There are three different types of wxWindows DLLs that can be | |
107 | produced by the VC makefile simply by providing a flag on the nmake | |
108 | command-line, I call the three types DEBUG, FINAL, and HYBRID. | |
109 | (The last one is brand new, you'll need my version of the 2.2.2 | |
110 | sources to get the HYBRID capability.) Here are some more details: | |
111 | ||
112 | DEBUG Specified with "FINAL=0" and produces a DLL named | |
113 | wx[version]d.dll. This DLL is compiled with full | |
114 | debugging information and with the __WXDEBUG__ set which | |
115 | enables some debugging-only code in wxWindows such as | |
116 | assertions and failure log messages. The /MDd flag is | |
117 | used which means that it is linked with the debugging | |
118 | version of the C runtime library and also that you must | |
119 | use the debugging version of Python, (python_d.exe and | |
120 | pythonXX_d.dll) which also means that all extensions | |
121 | loaded by Python should also have the _d in the name. | |
122 | With this option you can use the MSVC debugger to trace | |
123 | though the Python interpreter, as well as the code for the | |
124 | wxPython extension and the wxWindows DLL. | |
125 | ||
126 | FINAL Specified with "FINAL=1" and produces a DLL named | |
127 | wx[version].dll. This DLL is compiled with optimizations | |
128 | turned on and without debugging information and without | |
129 | __WXDEBUG__. The /MD flag is used which means that you | |
130 | can use this version with the standard python.exe. This | |
131 | is the version that I use when making the binary installer | |
132 | for win32. | |
133 | ||
134 | HYBRID Specified with "FINAL=hybrid" and produces a DLL named | |
135 | wx[version]h.dll. This DLL is almost the same as the | |
136 | DEBUG version except the /MD flag is used which means that | |
137 | you can use the standard python.exe but you still get the | |
138 | debugging info and the __WXDEBUG__ code enabled. With the | |
139 | debugger you can trace through the the code for the | |
140 | wxPython extension and the wxWindows DLL, but not the | |
141 | Python interpreter. You might use this version when you | |
142 | want to deploy a wxPython app with the __WXDEBUG__ code | |
143 | enabled. I use this mode most of the time during | |
144 | development simply because it's easier than having to | |
145 | remember to type python_d all the time. | |
146 | ||
147 | Since different DLL names and object file directories are used you | |
148 | can build all three types if you like. | |
149 | ||
150 | C. Change to the wx2\src\msw directory and type the following command, | |
151 | using the value for FINAL that you want: | |
152 | ||
153 | nmake -f makefile.vc dll pch FINAL=hybrid | |
154 | ||
155 | Your machine will then crunch away for possibly a long time, | |
156 | depending on your hardware, and when it's done you should have a | |
157 | DLL and some library files in \wx2\lib. | |
158 | ||
159 | D. You'll either need to add \wx2\lib to the PATH or copy the DLL file | |
160 | to a directory already on the PATH so the DLL can be found at runtime. | |
161 | ||
162 | E. You can test your build by changing to one of the directories under | |
163 | \wx2\samples or \wx2\demos and typing (using the right FINAL flag): | |
164 | ||
165 | nmake -f makefile.vc FINAL=hybrid WXUSINGDLL=1 | |
166 | ||
167 | and then executing the resulting .exe file. | |
168 | ||
169 | ||
170 | ||
171 | 3. Get the wxPython sources | |
172 | --------------------------- | |
173 | ||
174 | A. You have the same options (and same advantages/disadvantages) for | |
175 | getting the wxPython source, either a released snapshot or from | |
176 | CVS. The released version file is named wxPython-[version].tar.gz | |
177 | and is available at http://wxpython.org/download.php. You can use | |
178 | WinZip to unpack it if you don't have tar and gzip. If you want to | |
179 | use CVS you'll find wxPython in the wxWindows CVS tree (see above) | |
180 | in the wxWindows/wxPython directory. | |
181 | ||
182 | ||
183 | ||
184 | 4. Build and Install wxPython | |
185 | ----------------------------- | |
186 | ||
187 | A. As mentioned previouslly, wxPython is built with the standard | |
188 | Python Distutils tool. If you are using Python 2.0c1 or later you | |
189 | are all set, otherwise you need to download and install Distutils | |
190 | 1.0 from http://www.python.org/sigs/distutils-sig/. | |
191 | ||
192 | B. Change to the root wxPython directory and look at the setup.py | |
193 | file. This is the script that configures and defines all the | |
194 | information that Distutils needs to build wxPython. There are some | |
195 | options near the begining of the script that you may want or need | |
196 | to change based on what options you have selected up to this point, | |
197 | (type of DLL built, sources from tar.gz or from CVS, etc.) You can | |
198 | either change these flags directly in setup.py or supply them on | |
199 | the command-line. | |
200 | ||
201 | BUILD_GLCANVAS Set to zero if you don't want to build the | |
202 | Open GL canvas extension module. | |
203 | ||
204 | BUILD_OGL Set to zero if you don't want to build the | |
205 | Object Graphics Library extension module. | |
206 | ||
207 | BUILD_STC Set to zero if you don't want to build the | |
208 | wxStyledTextCtrl (the Scintilla wrapper) | |
209 | extension module. | |
210 | ||
211 | USE_SWIG If you have edited any of the *.i files you | |
212 | will need to set this flag to non-zero so SWIG | |
213 | will be executed to regenerate the wrapper C++ | |
214 | and shadow python files. | |
215 | ||
216 | IN_CVS_TREE If you are using the CVS version of the | |
217 | wxWindows and wxPython sources then you will | |
218 | need to set this flag to non-zero. This is | |
219 | needed because some source files from the | |
220 | wxWindows tree are copied to be under the | |
221 | wxPython tree in order to keep Distutils happy. | |
222 | With this flag set then setup.py will | |
223 | automatically keep these copied sources up to | |
224 | date if the original version is ever updated. | |
225 | If you are using the tar.gz version of the | |
226 | Python sources then these copied sources are | |
227 | already present in your source tree. | |
228 | ||
229 | ||
230 | C. To build and install wxPython you simply need to execute the | |
231 | setup.py script. If you have more than one version of Python | |
232 | installed, be sure to execute setup.py with the version you want to | |
233 | build wxPython for. | |
234 | ||
235 | Depending on what kind of wxWindows DLL you built there are | |
236 | different command-line parameters you'll want to pass to setup (in | |
237 | addition to possibly one or more of the above): | |
238 | ||
239 | FINAL: python setup.py install | |
240 | ||
241 | DEBUG: python setup.py build --debug install | |
242 | ||
243 | HYBRID: python setup.py HYBRID=1 install | |
244 | ||
245 | NOTE: If you get an internal compiler error from MSVC then you | |
246 | need to edit setup.py and add in the /GX- flag that is normally | |
247 | commented out. Just search for "GX-" and uncomment it so it is put | |
248 | into the cflags list. | |
249 | ||
250 | ||
251 | D. At this point you should be able to change into the wxPython\demo | |
252 | directory and run the demo: | |
253 | ||
254 | python demo.py | |
255 | ||
256 | E. If you would like to make a test build that doesn't overwrite the | |
257 | installed version of wxPython you can do so with one of these | |
258 | commands instead of the install command above: | |
259 | ||
260 | FINAL: python setup.py build_ext --inplace | |
261 | ||
262 | DEBUG: python setup.py build_ext --debug --inplace | |
263 | ||
264 | HYBRID: python setup.py HYBRID=1 build_ext --inplace | |
265 | ||
266 | This will build the wxPython package in the local wxPython | |
267 | directory instead of installing it under your Python installation. | |
268 | To run using this test version just add the base wxPython source | |
269 | directory to the PYTHONPATH: | |
270 | ||
271 | set PYTHONPATH=c:\wx2\wxPython | |
272 | cd c:\wx2\wxPython\demo | |
273 | python demo.py | |
274 | ||
275 | ||
276 | That's all folks! | |
277 | ||
278 | ||
279 | ----------------- | |
280 | robin@alldunn.com | |
281 |