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