Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 1 | :tocdepth: 2 |
| 2 | |
Miss Islington (bot) | b571958 | 2018-04-09 07:56:44 -0700 | [diff] [blame] | 3 | .. highlightlang:: none |
| 4 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 5 | .. _windows-faq: |
| 6 | |
| 7 | ===================== |
| 8 | Python on Windows FAQ |
| 9 | ===================== |
| 10 | |
Georg Brandl | 44ea77b | 2013-03-28 13:28:44 +0100 | [diff] [blame] | 11 | .. only:: html |
| 12 | |
| 13 | .. contents:: |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 14 | |
Georg Brandl | 62423cb | 2009-12-19 17:59:59 +0000 | [diff] [blame] | 15 | .. XXX need review for Python 3. |
| 16 | XXX need review for Windows Vista/Seven? |
| 17 | |
| 18 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 19 | How do I run a Python program under Windows? |
| 20 | -------------------------------------------- |
| 21 | |
| 22 | This is not necessarily a straightforward question. If you are already familiar |
| 23 | with running programs from the Windows command line then everything will seem |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 24 | obvious; otherwise, you might need a little more guidance. |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 25 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 26 | Unless you use some sort of integrated development environment, you will end up |
| 27 | *typing* Windows commands into what is variously referred to as a "DOS window" |
| 28 | or "Command prompt window". Usually you can create such a window from your |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 29 | Start menu; under Windows 7 the menu selection is :menuselection:`Start --> |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 30 | Programs --> Accessories --> Command Prompt`. You should be able to recognize |
| 31 | when you have started such a window because you will see a Windows "command |
Miss Islington (bot) | b571958 | 2018-04-09 07:56:44 -0700 | [diff] [blame] | 32 | prompt", which usually looks like this: |
| 33 | |
| 34 | .. code-block:: doscon |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 35 | |
| 36 | C:\> |
| 37 | |
| 38 | The letter may be different, and there might be other things after it, so you |
Miss Islington (bot) | b571958 | 2018-04-09 07:56:44 -0700 | [diff] [blame] | 39 | might just as easily see something like: |
| 40 | |
| 41 | .. code-block:: doscon |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 42 | |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 43 | D:\YourName\Projects\Python> |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 44 | |
| 45 | depending on how your computer has been set up and what else you have recently |
| 46 | done with it. Once you have started such a window, you are well on the way to |
| 47 | running Python programs. |
| 48 | |
| 49 | You need to realize that your Python scripts have to be processed by another |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 50 | program called the Python *interpreter*. The interpreter reads your script, |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 51 | compiles it into bytecodes, and then executes the bytecodes to run your |
| 52 | program. So, how do you arrange for the interpreter to handle your Python? |
| 53 | |
| 54 | First, you need to make sure that your command window recognises the word |
| 55 | "python" as an instruction to start the interpreter. If you have opened a |
| 56 | command window, you should try entering the command ``python`` and hitting |
Miss Islington (bot) | b571958 | 2018-04-09 07:56:44 -0700 | [diff] [blame] | 57 | return: |
| 58 | |
| 59 | .. code-block:: doscon |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 60 | |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 61 | C:\Users\YourName> python |
| 62 | |
Miss Islington (bot) | b571958 | 2018-04-09 07:56:44 -0700 | [diff] [blame] | 63 | You should then see something like: |
| 64 | |
| 65 | .. code-block:: pycon |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 66 | |
| 67 | Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 68 | Type "help", "copyright", "credits" or "license" for more information. |
| 69 | >>> |
| 70 | |
| 71 | You have started the interpreter in "interactive mode". That means you can enter |
| 72 | Python statements or expressions interactively and have them executed or |
| 73 | evaluated while you wait. This is one of Python's strongest features. Check it |
Miss Islington (bot) | b571958 | 2018-04-09 07:56:44 -0700 | [diff] [blame] | 74 | by entering a few expressions of your choice and seeing the results: |
| 75 | |
| 76 | .. code-block:: pycon |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 77 | |
Georg Brandl | 62423cb | 2009-12-19 17:59:59 +0000 | [diff] [blame] | 78 | >>> print("Hello") |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 79 | Hello |
| 80 | >>> "Hello" * 3 |
Georg Brandl | 9205e9e | 2014-10-06 17:51:09 +0200 | [diff] [blame] | 81 | 'HelloHelloHello' |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 82 | |
| 83 | Many people use the interactive mode as a convenient yet highly programmable |
Serhiy Storchaka | 0424eaf | 2015-09-12 17:45:25 +0300 | [diff] [blame] | 84 | calculator. When you want to end your interactive Python session, hold the :kbd:`Ctrl` |
| 85 | key down while you enter a :kbd:`Z`, then hit the ":kbd:`Enter`" key to get back to your |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 86 | Windows command prompt. |
| 87 | |
| 88 | You may also find that you have a Start-menu entry such as :menuselection:`Start |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 89 | --> Programs --> Python 3.3 --> Python (command line)` that results in you |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 90 | seeing the ``>>>`` prompt in a new window. If so, the window will disappear |
Serhiy Storchaka | 0424eaf | 2015-09-12 17:45:25 +0300 | [diff] [blame] | 91 | after you enter the :kbd:`Ctrl-Z` character; Windows is running a single "python" |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 92 | command in the window, and closes it when you terminate the interpreter. |
| 93 | |
| 94 | If the ``python`` command, instead of displaying the interpreter prompt ``>>>``, |
| 95 | gives you a message like:: |
| 96 | |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 97 | 'python' is not recognized as an internal or external command, operable program or batch file. |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 98 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 99 | or:: |
| 100 | |
| 101 | Bad command or filename |
| 102 | |
| 103 | then you need to make sure that your computer knows where to find the Python |
| 104 | interpreter. To do this you will have to modify a setting called PATH, which is |
| 105 | a list of directories where Windows will look for programs. |
| 106 | |
| 107 | You should arrange for Python's installation directory to be added to the PATH |
| 108 | of every command window as it starts. If you installed Python fairly recently |
| 109 | then the command :: |
| 110 | |
| 111 | dir C:\py* |
| 112 | |
| 113 | will probably tell you where it is installed; the usual location is something |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 114 | like ``C:\Python33``. Otherwise you will be reduced to a search of your whole |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 115 | disk ... use :menuselection:`Tools --> Find` or hit the :guilabel:`Search` |
| 116 | button and look for "python.exe". Supposing you discover that Python is |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 117 | installed in the ``C:\Python33`` directory (the default at the time of writing), |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 118 | you should make sure that entering the command :: |
| 119 | |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 120 | c:\Python33\python |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 121 | |
Serhiy Storchaka | 0424eaf | 2015-09-12 17:45:25 +0300 | [diff] [blame] | 122 | starts up the interpreter as above (and don't forget you'll need a ":kbd:`Ctrl-Z`" and |
| 123 | an ":kbd:`Enter`" to get out of it). Once you have verified the directory, you can |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 124 | add it to the system path to make it easier to start Python by just running |
| 125 | the ``python`` command. This is currently an option in the installer as of |
| 126 | CPython 3.3. |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 127 | |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 128 | More information about environment variables can be found on the |
| 129 | :ref:`Using Python on Windows <setting-envvars>` page. |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 130 | |
Ezio Melotti | 0639d5a | 2009-12-19 23:26:38 +0000 | [diff] [blame] | 131 | How do I make Python scripts executable? |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 132 | ---------------------------------------- |
| 133 | |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 134 | On Windows, the standard Python installer already associates the .py |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 135 | extension with a file type (Python.File) and gives that file type an open |
| 136 | command that runs the interpreter (``D:\Program Files\Python\python.exe "%1" |
| 137 | %*``). This is enough to make scripts executable from the command prompt as |
| 138 | 'foo.py'. If you'd rather be able to execute the script by simple typing 'foo' |
| 139 | with no extension you need to add .py to the PATHEXT environment variable. |
| 140 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 141 | Why does Python sometimes take so long to start? |
| 142 | ------------------------------------------------ |
| 143 | |
| 144 | Usually Python starts very quickly on Windows, but occasionally there are bug |
| 145 | reports that Python suddenly begins to take a long time to start up. This is |
| 146 | made even more puzzling because Python will work fine on other Windows systems |
| 147 | which appear to be configured identically. |
| 148 | |
| 149 | The problem may be caused by a misconfiguration of virus checking software on |
| 150 | the problem machine. Some virus scanners have been known to introduce startup |
| 151 | overhead of two orders of magnitude when the scanner is configured to monitor |
| 152 | all reads from the filesystem. Try checking the configuration of virus scanning |
| 153 | software on your systems to ensure that they are indeed configured identically. |
| 154 | McAfee, when configured to scan all file system read activity, is a particular |
| 155 | offender. |
| 156 | |
| 157 | |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 158 | How do I make an executable from a Python script? |
| 159 | ------------------------------------------------- |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 160 | |
Sanyam Khurana | 1b4587a | 2017-12-06 22:09:33 +0530 | [diff] [blame] | 161 | See `cx_Freeze <https://anthony-tuininga.github.io/cx_Freeze/>`_ for a distutils extension |
| 162 | that allows you to create console and GUI executables from Python code. |
Zachary Ware | 9fc0e99 | 2014-01-17 08:59:44 -0600 | [diff] [blame] | 163 | `py2exe <http://www.py2exe.org/>`_, the most popular extension for building |
| 164 | Python 2.x-based executables, does not yet support Python 3 but a version that |
| 165 | does is in development. |
| 166 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 167 | |
| 168 | Is a ``*.pyd`` file the same as a DLL? |
| 169 | -------------------------------------- |
| 170 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 171 | Yes, .pyd files are dll's, but there are a few differences. If you have a DLL |
Zachary Ware | 9fc0e99 | 2014-01-17 08:59:44 -0600 | [diff] [blame] | 172 | named ``foo.pyd``, then it must have a function ``PyInit_foo()``. You can then |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 173 | write Python "import foo", and Python will search for foo.pyd (as well as |
Zachary Ware | 9fc0e99 | 2014-01-17 08:59:44 -0600 | [diff] [blame] | 174 | foo.py, foo.pyc) and if it finds it, will attempt to call ``PyInit_foo()`` to |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 175 | initialize it. You do not link your .exe with foo.lib, as that would cause |
| 176 | Windows to require the DLL to be present. |
| 177 | |
| 178 | Note that the search path for foo.pyd is PYTHONPATH, not the same as the path |
| 179 | that Windows uses to search for foo.dll. Also, foo.pyd need not be present to |
| 180 | run your program, whereas if you linked your program with a dll, the dll is |
| 181 | required. Of course, foo.pyd is required if you want to say ``import foo``. In |
| 182 | a DLL, linkage is declared in the source code with ``__declspec(dllexport)``. |
| 183 | In a .pyd, linkage is defined in a list of available functions. |
| 184 | |
| 185 | |
| 186 | How can I embed Python into a Windows application? |
| 187 | -------------------------------------------------- |
| 188 | |
| 189 | Embedding the Python interpreter in a Windows app can be summarized as follows: |
| 190 | |
| 191 | 1. Do _not_ build Python into your .exe file directly. On Windows, Python must |
| 192 | be a DLL to handle importing modules that are themselves DLL's. (This is the |
Georg Brandl | 4985ff2 | 2010-10-17 10:14:38 +0000 | [diff] [blame] | 193 | first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is |
| 194 | typically installed in ``C:\Windows\System``. *NN* is the Python version, a |
Brian Curtin | 655b0c4 | 2012-12-16 23:58:09 -0600 | [diff] [blame] | 195 | number such as "33" for Python 3.3. |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 196 | |
Georg Brandl | 4985ff2 | 2010-10-17 10:14:38 +0000 | [diff] [blame] | 197 | You can link to Python in two different ways. Load-time linking means |
| 198 | linking against :file:`python{NN}.lib`, while run-time linking means linking |
| 199 | against :file:`python{NN}.dll`. (General note: :file:`python{NN}.lib` is the |
Georg Brandl | fc9794a | 2010-10-17 10:15:50 +0000 | [diff] [blame] | 200 | so-called "import lib" corresponding to :file:`python{NN}.dll`. It merely |
Georg Brandl | 4985ff2 | 2010-10-17 10:14:38 +0000 | [diff] [blame] | 201 | defines symbols for the linker.) |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 202 | |
Georg Brandl | 4985ff2 | 2010-10-17 10:14:38 +0000 | [diff] [blame] | 203 | Run-time linking greatly simplifies link options; everything happens at run |
| 204 | time. Your code must load :file:`python{NN}.dll` using the Windows |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 205 | ``LoadLibraryEx()`` routine. The code must also use access routines and data |
| 206 | in :file:`python{NN}.dll` (that is, Python's C API's) using pointers obtained |
| 207 | by the Windows ``GetProcAddress()`` routine. Macros can make using these |
| 208 | pointers transparent to any C code that calls routines in Python's C API. |
| 209 | |
| 210 | Borland note: convert :file:`python{NN}.lib` to OMF format using Coff2Omf.exe |
| 211 | first. |
| 212 | |
Georg Brandl | 4985ff2 | 2010-10-17 10:14:38 +0000 | [diff] [blame] | 213 | .. XXX what about static linking? |
| 214 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 215 | 2. If you use SWIG, it is easy to create a Python "extension module" that will |
| 216 | make the app's data and methods available to Python. SWIG will handle just |
| 217 | about all the grungy details for you. The result is C code that you link |
| 218 | *into* your .exe file (!) You do _not_ have to create a DLL file, and this |
| 219 | also simplifies linking. |
| 220 | |
| 221 | 3. SWIG will create an init function (a C function) whose name depends on the |
| 222 | name of the extension module. For example, if the name of the module is leo, |
| 223 | the init function will be called initleo(). If you use SWIG shadow classes, |
| 224 | as you should, the init function will be called initleoc(). This initializes |
| 225 | a mostly hidden helper class used by the shadow class. |
| 226 | |
| 227 | The reason you can link the C code in step 2 into your .exe file is that |
| 228 | calling the initialization function is equivalent to importing the module |
| 229 | into Python! (This is the second key undocumented fact.) |
| 230 | |
| 231 | 4. In short, you can use the following code to initialize the Python interpreter |
| 232 | with your extension module. |
| 233 | |
| 234 | .. code-block:: c |
| 235 | |
| 236 | #include "python.h" |
| 237 | ... |
| 238 | Py_Initialize(); // Initialize Python. |
| 239 | initmyAppc(); // Initialize (import) the helper class. |
Serhiy Storchaka | f47036c | 2013-12-24 11:04:36 +0200 | [diff] [blame] | 240 | PyRun_SimpleString("import myApp"); // Import the shadow class. |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 241 | |
| 242 | 5. There are two problems with Python's C API which will become apparent if you |
| 243 | use a compiler other than MSVC, the compiler used to build pythonNN.dll. |
| 244 | |
| 245 | Problem 1: The so-called "Very High Level" functions that take FILE * |
| 246 | arguments will not work in a multi-compiler environment because each |
| 247 | compiler's notion of a struct FILE will be different. From an implementation |
| 248 | standpoint these are very _low_ level functions. |
| 249 | |
| 250 | Problem 2: SWIG generates the following code when generating wrappers to void |
| 251 | functions: |
| 252 | |
| 253 | .. code-block:: c |
| 254 | |
| 255 | Py_INCREF(Py_None); |
| 256 | _resultobj = Py_None; |
| 257 | return _resultobj; |
| 258 | |
| 259 | Alas, Py_None is a macro that expands to a reference to a complex data |
| 260 | structure called _Py_NoneStruct inside pythonNN.dll. Again, this code will |
| 261 | fail in a mult-compiler environment. Replace such code by: |
| 262 | |
| 263 | .. code-block:: c |
| 264 | |
| 265 | return Py_BuildValue(""); |
| 266 | |
| 267 | It may be possible to use SWIG's ``%typemap`` command to make the change |
| 268 | automatically, though I have not been able to get this to work (I'm a |
| 269 | complete SWIG newbie). |
| 270 | |
| 271 | 6. Using a Python shell script to put up a Python interpreter window from inside |
| 272 | your Windows app is not a good idea; the resulting window will be independent |
| 273 | of your app's windowing system. Rather, you (or the wxPythonWindow class) |
| 274 | should create a "native" interpreter window. It is easy to connect that |
| 275 | window to the Python interpreter. You can redirect Python's i/o to _any_ |
| 276 | object that supports read and write, so all you need is a Python object |
| 277 | (defined in your extension module) that contains read() and write() methods. |
| 278 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 279 | How do I keep editors from inserting tabs into my Python source? |
| 280 | ---------------------------------------------------------------- |
| 281 | |
| 282 | The FAQ does not recommend using tabs, and the Python style guide, :pep:`8`, |
| 283 | recommends 4 spaces for distributed Python code; this is also the Emacs |
| 284 | python-mode default. |
| 285 | |
| 286 | Under any editor, mixing tabs and spaces is a bad idea. MSVC is no different in |
| 287 | this respect, and is easily configured to use spaces: Take :menuselection:`Tools |
| 288 | --> Options --> Tabs`, and for file type "Default" set "Tab size" and "Indent |
| 289 | size" to 4, and select the "Insert spaces" radio button. |
| 290 | |
Victor Stinner | 2b50186 | 2017-02-13 15:30:05 +0100 | [diff] [blame] | 291 | Python raises :exc:`IndentationError` or :exc:`TabError` if mixed tabs |
Jim DeLaHunt | 3d707be | 2017-02-13 05:57:13 -0800 | [diff] [blame] | 292 | and spaces are causing problems in leading whitespace. |
Victor Stinner | 2b50186 | 2017-02-13 15:30:05 +0100 | [diff] [blame] | 293 | You may also run the :mod:`tabnanny` module to check a directory tree |
Jim DeLaHunt | 3d707be | 2017-02-13 05:57:13 -0800 | [diff] [blame] | 294 | in batch mode. |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 295 | |
| 296 | |
| 297 | How do I check for a keypress without blocking? |
| 298 | ----------------------------------------------- |
| 299 | |
| 300 | Use the msvcrt module. This is a standard Windows-specific extension module. |
| 301 | It defines a function ``kbhit()`` which checks whether a keyboard hit is |
| 302 | present, and ``getch()`` which gets one character without echoing it. |
| 303 | |
| 304 | |
| 305 | How do I emulate os.kill() in Windows? |
| 306 | -------------------------------------- |
| 307 | |
Miss Islington (bot) | b571958 | 2018-04-09 07:56:44 -0700 | [diff] [blame] | 308 | Prior to Python 2.7 and 3.2, to terminate a process, you can use :mod:`ctypes`: |
| 309 | |
| 310 | .. code-block:: python |
Georg Brandl | ff24c8e | 2010-03-21 09:52:24 +0000 | [diff] [blame] | 311 | |
| 312 | import ctypes |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 313 | |
| 314 | def kill(pid): |
| 315 | """kill function for Win32""" |
Georg Brandl | ff24c8e | 2010-03-21 09:52:24 +0000 | [diff] [blame] | 316 | kernel32 = ctypes.windll.kernel32 |
| 317 | handle = kernel32.OpenProcess(1, 0, pid) |
| 318 | return (0 != kernel32.TerminateProcess(handle, 0)) |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 319 | |
Brian Curtin | f4ed206 | 2010-04-12 18:10:10 +0000 | [diff] [blame] | 320 | In 2.7 and 3.2, :func:`os.kill` is implemented similar to the above function, |
Serhiy Storchaka | 0424eaf | 2015-09-12 17:45:25 +0300 | [diff] [blame] | 321 | with the additional feature of being able to send :kbd:`Ctrl+C` and :kbd:`Ctrl+Break` |
Brian Curtin | f4ed206 | 2010-04-12 18:10:10 +0000 | [diff] [blame] | 322 | to console subprocesses which are designed to handle those signals. See |
| 323 | :func:`os.kill` for further details. |
| 324 | |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 325 | How do I extract the downloaded documentation on Windows? |
| 326 | --------------------------------------------------------- |
| 327 | |
| 328 | Sometimes, when you download the documentation package to a Windows machine |
| 329 | using a web browser, the file extension of the saved file ends up being .EXE. |
| 330 | This is a mistake; the extension should be .TGZ. |
| 331 | |
| 332 | Simply rename the downloaded file to have the .TGZ extension, and WinZip will be |
| 333 | able to handle it. (If your copy of WinZip doesn't, get a newer one from |
Serhiy Storchaka | 6dff020 | 2016-05-07 10:49:07 +0300 | [diff] [blame] | 334 | https://www.winzip.com.) |
Georg Brandl | d741315 | 2009-10-11 21:25:26 +0000 | [diff] [blame] | 335 | |