Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-backports > by-pkgid > 3ba3bd1608c672ba2129b098a48e9e4d > files > 551

python3-docs-3.2.2-3mdv2010.2.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Python on Windows FAQ &mdash; Python v3.2.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.2.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v3.2.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v3.2.2 documentation" href="../index.html" />
    <link rel="up" title="Python Frequently Asked Questions" href="index.html" />
    <link rel="next" title="Graphic User Interface FAQ" href="gui.html" />
    <link rel="prev" title="Extending/Embedding FAQ" href="extending.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="gui.html" title="Graphic User Interface FAQ"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="extending.html" title="Extending/Embedding FAQ"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="python-on-windows-faq">
<span id="windows-faq"></span><h1><a class="toc-backref" href="#id1">Python on Windows FAQ</a><a class="headerlink" href="#python-on-windows-faq" title="Permalink to this headline">¶</a></h1>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#python-on-windows-faq" id="id1">Python on Windows FAQ</a><ul>
<li><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows" id="id2">How do I run a Python program under Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-make-python-scripts-executable" id="id3">How do I make Python scripts executable?</a></li>
<li><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start" id="id4">Why does Python sometimes take so long to start?</a></li>
<li><a class="reference internal" href="#where-is-freeze-for-windows" id="id5">Where is Freeze for Windows?</a></li>
<li><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll" id="id6">Is a <tt class="docutils literal"><span class="pre">*.pyd</span></tt> file the same as a DLL?</a></li>
<li><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application" id="id7">How can I embed Python into a Windows application?</a></li>
<li><a class="reference internal" href="#how-do-i-use-python-for-cgi" id="id8">How do I use Python for CGI?</a></li>
<li><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source" id="id9">How do I keep editors from inserting tabs into my Python source?</a></li>
<li><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking" id="id10">How do I check for a keypress without blocking?</a></li>
<li><a class="reference internal" href="#how-do-i-emulate-os-kill-in-windows" id="id11">How do I emulate os.kill() in Windows?</a></li>
<li><a class="reference internal" href="#why-does-os-path-isdir-fail-on-nt-shared-directories" id="id12">Why does os.path.isdir() fail on NT shared directories?</a></li>
<li><a class="reference internal" href="#cgi-py-or-other-cgi-programming-doesn-t-work-sometimes-on-nt-or-win95" id="id13">cgi.py (or other CGI programming) doesn&#8217;t work sometimes on NT or win95!</a></li>
<li><a class="reference internal" href="#why-doesn-t-os-popen-work-in-pythonwin-on-nt" id="id14">Why doesn&#8217;t os.popen() work in PythonWin on NT?</a></li>
<li><a class="reference internal" href="#why-doesn-t-os-popen-win32pipe-popen-work-on-win9x" id="id15">Why doesn&#8217;t os.popen()/win32pipe.popen() work on Win9x?</a></li>
<li><a class="reference internal" href="#pyrun-simplefile-crashes-on-windows-but-not-on-unix-why" id="id16">PyRun_SimpleFile() crashes on Windows but not on Unix; why?</a></li>
<li><a class="reference internal" href="#importing-tkinter-fails-on-windows-95-98-why" id="id17">Importing _tkinter fails on Windows 95/98: why?</a></li>
<li><a class="reference internal" href="#how-do-i-extract-the-downloaded-documentation-on-windows" id="id18">How do I extract the downloaded documentation on Windows?</a></li>
<li><a class="reference internal" href="#missing-cw3215mt-dll-or-missing-cw3215-dll" id="id19">Missing cw3215mt.dll (or missing cw3215.dll)</a></li>
<li><a class="reference internal" href="#warning-about-ctl3d32-version-from-installer" id="id20">Warning about CTL3D32 version from installer</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="how-do-i-run-a-python-program-under-windows">
<h2><a class="toc-backref" href="#id2">How do I run a Python program under Windows?</a><a class="headerlink" href="#how-do-i-run-a-python-program-under-windows" title="Permalink to this headline">¶</a></h2>
<p>This is not necessarily a straightforward question. If you are already familiar
with running programs from the Windows command line then everything will seem
obvious; otherwise, you might need a little more guidance.  There are also
differences between Windows 95, 98, NT, ME, 2000 and XP which can add to the
confusion.</p>
<div class="sidebar">
<p class="first sidebar-title"><a class="reference external" href="http://www.showmedo.com/videos/series?name=pythonOzsvaldPyNewbieSeries"><img alt="Python Development on XP" src="../_images/python-video-icon.png" /></a></p>
<p class="sidebar-subtitle"><a class="reference external" href="http://www.showmedo.com/videos/series?name=pythonOzsvaldPyNewbieSeries">Python Development on XP</a></p>
<p class="last">This series of screencasts aims to get you up and running with Python on
Windows XP.  The knowledge is distilled into 1.5 hours and will get you up
and running with the right Python distribution, coding in your choice of IDE,
and debugging and writing solid code with unit-tests.</p>
</div>
<p>Unless you use some sort of integrated development environment, you will end up
<em>typing</em> Windows commands into what is variously referred to as a &#8220;DOS window&#8221;
or &#8220;Command prompt window&#8221;.  Usually you can create such a window from your
Start menu; under Windows 2000 the menu selection is <em class="menuselection">Start ‣
Programs ‣ Accessories ‣ Command Prompt</em>.  You should be able to recognize
when you have started such a window because you will see a Windows &#8220;command
prompt&#8221;, which usually looks like this:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">C</span><span class="p">:</span>\<span class="o">&gt;</span>
</pre></div>
</div>
<p>The letter may be different, and there might be other things after it, so you
might just as easily see something like:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">D</span><span class="p">:</span>\<span class="n">Steve</span>\<span class="n">Projects</span>\<span class="n">Python</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>depending on how your computer has been set up and what else you have recently
done with it.  Once you have started such a window, you are well on the way to
running Python programs.</p>
<p>You need to realize that your Python scripts have to be processed by another
program called the Python interpreter.  The interpreter reads your script,
compiles it into bytecodes, and then executes the bytecodes to run your
program. So, how do you arrange for the interpreter to handle your Python?</p>
<p>First, you need to make sure that your command window recognises the word
&#8220;python&#8221; as an instruction to start the interpreter.  If you have opened a
command window, you should try entering the command <tt class="docutils literal"><span class="pre">python</span></tt> and hitting
return.  You should then see something like:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">Python</span> <span class="mf">2.2</span> <span class="p">(</span><span class="c">#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32</span>
<span class="n">Type</span> <span class="s">&quot;help&quot;</span><span class="p">,</span> <span class="s">&quot;copyright&quot;</span><span class="p">,</span> <span class="s">&quot;credits&quot;</span> <span class="ow">or</span> <span class="s">&quot;license&quot;</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>You have started the interpreter in &#8220;interactive mode&#8221;. That means you can enter
Python statements or expressions interactively and have them executed or
evaluated while you wait.  This is one of Python&#8217;s strongest features.  Check it
by entering a few expressions of your choice and seeing the results:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s">&quot;Hello&quot;</span><span class="p">)</span>
<span class="go">Hello</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s">&quot;Hello&quot;</span> <span class="o">*</span> <span class="mi">3</span>
<span class="go">HelloHelloHello</span>
</pre></div>
</div>
<p>Many people use the interactive mode as a convenient yet highly programmable
calculator.  When you want to end your interactive Python session, hold the Ctrl
key down while you enter a Z, then hit the &#8220;Enter&#8221; key to get back to your
Windows command prompt.</p>
<p>You may also find that you have a Start-menu entry such as <em class="menuselection">Start
‣ Programs ‣ Python 2.2 ‣ Python (command line)</em> that results in you
seeing the <tt class="docutils literal"><span class="pre">&gt;&gt;&gt;</span></tt> prompt in a new window.  If so, the window will disappear
after you enter the Ctrl-Z character; Windows is running a single &#8220;python&#8221;
command in the window, and closes it when you terminate the interpreter.</p>
<p>If the <tt class="docutils literal"><span class="pre">python</span></tt> command, instead of displaying the interpreter prompt <tt class="docutils literal"><span class="pre">&gt;&gt;&gt;</span></tt>,
gives you a message like:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="s">&#39;python&#39;</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">recognized</span> <span class="k">as</span> <span class="n">an</span> <span class="n">internal</span> <span class="ow">or</span> <span class="n">external</span> <span class="n">command</span><span class="p">,</span>
<span class="n">operable</span> <span class="n">program</span> <span class="ow">or</span> <span class="n">batch</span> <span class="n">file</span><span class="o">.</span>
</pre></div>
</div>
<div class="sidebar">
<p class="first sidebar-title"><a class="reference external" href="http://showmedo.com/videos/video?name=960000&amp;fromSeriesID=96"><img alt="Adding Python to DOS Path" src="../_images/python-video-icon.png" /></a></p>
<p class="sidebar-subtitle"><a class="reference external" href="http://showmedo.com/videos/video?name=960000&amp;fromSeriesID=96">Adding Python to DOS Path</a></p>
<p class="last">Python is not added to the DOS path by default.  This screencast will walk
you through the steps to add the correct entry to the <cite>System Path</cite>, allowing
Python to be executed from the command-line by all users.</p>
</div>
<p>or:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">Bad</span> <span class="n">command</span> <span class="ow">or</span> <span class="n">filename</span>
</pre></div>
</div>
<p>then you need to make sure that your computer knows where to find the Python
interpreter.  To do this you will have to modify a setting called PATH, which is
a list of directories where Windows will look for programs.</p>
<p>You should arrange for Python&#8217;s installation directory to be added to the PATH
of every command window as it starts.  If you installed Python fairly recently
then the command</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="nb">dir</span> <span class="n">C</span><span class="p">:</span>\<span class="n">py</span><span class="o">*</span>
</pre></div>
</div>
<p>will probably tell you where it is installed; the usual location is something
like <tt class="docutils literal"><span class="pre">C:\Python23</span></tt>.  Otherwise you will be reduced to a search of your whole
disk ... use <em class="menuselection">Tools ‣ Find</em> or hit the <em class="guilabel">Search</em>
button and look for &#8220;python.exe&#8221;.  Supposing you discover that Python is
installed in the <tt class="docutils literal"><span class="pre">C:\Python23</span></tt> directory (the default at the time of writing),
you should make sure that entering the command</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">c</span><span class="p">:</span>\<span class="n">Python23</span>\<span class="n">python</span>
</pre></div>
</div>
<p>starts up the interpreter as above (and don&#8217;t forget you&#8217;ll need a &#8220;CTRL-Z&#8221; and
an &#8220;Enter&#8221; to get out of it). Once you have verified the directory, you need to
add it to the start-up routines your computer goes through.  For older versions
of Windows the easiest way to do this is to edit the <tt class="docutils literal"><span class="pre">C:\AUTOEXEC.BAT</span></tt>
file. You would want to add a line like the following to <tt class="docutils literal"><span class="pre">AUTOEXEC.BAT</span></tt>:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">PATH</span> <span class="n">C</span><span class="p">:</span>\<span class="n">Python23</span><span class="p">;</span><span class="o">%</span><span class="n">PATH</span><span class="o">%</span>
</pre></div>
</div>
<p>For Windows NT, 2000 and (I assume) XP, you will need to add a string such as</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="p">;</span><span class="n">C</span><span class="p">:</span>\<span class="n">Python23</span>
</pre></div>
</div>
<p>to the current setting for the PATH environment variable, which you will find in
the properties window of &#8220;My Computer&#8221; under the &#8220;Advanced&#8221; tab.  Note that if
you have sufficient privilege you might get a choice of installing the settings
either for the Current User or for System.  The latter is preferred if you want
everybody to be able to run Python on the machine.</p>
<p>If you aren&#8217;t confident doing any of these manipulations yourself, ask for help!
At this stage you may want to reboot your system to make absolutely sure the new
setting has taken effect.  You probably won&#8217;t need to reboot for Windows NT, XP
or 2000.  You can also avoid it in earlier versions by editing the file
<tt class="docutils literal"><span class="pre">C:\WINDOWS\COMMAND\CMDINIT.BAT</span></tt> instead of <tt class="docutils literal"><span class="pre">AUTOEXEC.BAT</span></tt>.</p>
<p>You should now be able to start a new command window, enter <tt class="docutils literal"><span class="pre">python</span></tt> at the
<tt class="docutils literal"><span class="pre">C:\&gt;</span></tt> (or whatever) prompt, and see the <tt class="docutils literal"><span class="pre">&gt;&gt;&gt;</span></tt> prompt that indicates the
Python interpreter is reading interactive commands.</p>
<p>Let&#8217;s suppose you have a program called <tt class="docutils literal"><span class="pre">pytest.py</span></tt> in directory
<tt class="docutils literal"><span class="pre">C:\Steve\Projects\Python</span></tt>.  A session to run that program might look like
this:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">C</span><span class="p">:</span>\<span class="o">&gt;</span> <span class="n">cd</span> \<span class="n">Steve</span>\<span class="n">Projects</span>\<span class="n">Python</span>
<span class="n">C</span><span class="p">:</span>\<span class="n">Steve</span>\<span class="n">Projects</span>\<span class="n">Python</span><span class="o">&gt;</span> <span class="n">python</span> <span class="n">pytest</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>Because you added a file name to the command to start the interpreter, when it
starts up it reads the Python script in the named file, compiles it, executes
it, and terminates, so you see another <tt class="docutils literal"><span class="pre">C:\&gt;</span></tt> prompt.  You might also have
entered</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">C</span><span class="p">:</span>\<span class="o">&gt;</span> <span class="n">python</span> \<span class="n">Steve</span>\<span class="n">Projects</span>\<span class="n">Python</span>\<span class="n">pytest</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>if you hadn&#8217;t wanted to change your current directory.</p>
<p>Under NT, 2000 and XP you may well find that the installation process has also
arranged that the command <tt class="docutils literal"><span class="pre">pytest.py</span></tt> (or, if the file isn&#8217;t in the current
directory, <tt class="docutils literal"><span class="pre">C:\Steve\Projects\Python\pytest.py</span></tt>) will automatically recognize
the &#8221;.py&#8221; extension and run the Python interpreter on the named file. Using this
feature is fine, but <em>some</em> versions of Windows have bugs which mean that this
form isn&#8217;t exactly equivalent to using the interpreter explicitly, so be
careful.</p>
<p>The important things to remember are:</p>
<ol class="arabic">
<li><p class="first">Start Python from the Start Menu, or make sure the PATH is set correctly so
Windows can find the Python interpreter.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">python</span>
</pre></div>
</div>
<p>should give you a &#8216;&gt;&gt;&gt;&#8217; prompt from the Python interpreter. Don&#8217;t forget the
CTRL-Z and ENTER to terminate the interpreter (and, if you started the window
from the Start Menu, make the window disappear).</p>
</li>
<li><p class="first">Once this works, you run programs with commands:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">python</span> <span class="p">{</span><span class="n">program</span><span class="o">-</span><span class="n">file</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p class="first">When you know the commands to use you can build Windows shortcuts to run the
Python interpreter on any of your scripts, naming particular working
directories, and adding them to your menus.  Take a look at</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">python</span> <span class="o">--</span><span class="n">help</span>
</pre></div>
</div>
<p>if your needs are complex.</p>
</li>
<li><p class="first">Interactive mode (where you see the <tt class="docutils literal"><span class="pre">&gt;&gt;&gt;</span></tt> prompt) is best used for checking
that individual statements and expressions do what you think they will, and
for developing code by experiment.</p>
</li>
</ol>
</div>
<div class="section" id="how-do-i-make-python-scripts-executable">
<h2><a class="toc-backref" href="#id3">How do I make Python scripts executable?</a><a class="headerlink" href="#how-do-i-make-python-scripts-executable" title="Permalink to this headline">¶</a></h2>
<p>On Windows 2000, the standard Python installer already associates the .py
extension with a file type (Python.File) and gives that file type an open
command that runs the interpreter (<tt class="docutils literal"><span class="pre">D:\Program</span> <span class="pre">Files\Python\python.exe</span> <span class="pre">&quot;%1&quot;</span>
<span class="pre">%*</span></tt>).  This is enough to make scripts executable from the command prompt as
&#8216;foo.py&#8217;.  If you&#8217;d rather be able to execute the script by simple typing &#8216;foo&#8217;
with no extension you need to add .py to the PATHEXT environment variable.</p>
<p>On Windows NT, the steps taken by the installer as described above allow you to
run a script with &#8216;foo.py&#8217;, but a longtime bug in the NT command processor
prevents you from redirecting the input or output of any script executed in this
way.  This is often important.</p>
<p>The incantation for making a Python script executable under WinNT is to give the
file an extension of .cmd and add the following as the first line:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="nd">@setlocal</span> <span class="n">enableextensions</span> <span class="o">&amp;</span> <span class="n">python</span> <span class="o">-</span><span class="n">x</span> <span class="o">%~</span><span class="n">f0</span> <span class="o">%*</span> <span class="o">&amp;</span> <span class="n">goto</span> <span class="p">:</span><span class="n">EOF</span>
</pre></div>
</div>
</div>
<div class="section" id="why-does-python-sometimes-take-so-long-to-start">
<h2><a class="toc-backref" href="#id4">Why does Python sometimes take so long to start?</a><a class="headerlink" href="#why-does-python-sometimes-take-so-long-to-start" title="Permalink to this headline">¶</a></h2>
<p>Usually Python starts very quickly on Windows, but occasionally there are bug
reports that Python suddenly begins to take a long time to start up.  This is
made even more puzzling because Python will work fine on other Windows systems
which appear to be configured identically.</p>
<p>The problem may be caused by a misconfiguration of virus checking software on
the problem machine.  Some virus scanners have been known to introduce startup
overhead of two orders of magnitude when the scanner is configured to monitor
all reads from the filesystem.  Try checking the configuration of virus scanning
software on your systems to ensure that they are indeed configured identically.
McAfee, when configured to scan all file system read activity, is a particular
offender.</p>
</div>
<div class="section" id="where-is-freeze-for-windows">
<h2><a class="toc-backref" href="#id5">Where is Freeze for Windows?</a><a class="headerlink" href="#where-is-freeze-for-windows" title="Permalink to this headline">¶</a></h2>
<p>&#8220;Freeze&#8221; is a program that allows you to ship a Python program as a single
stand-alone executable file.  It is <em>not</em> a compiler; your programs don&#8217;t run
any faster, but they are more easily distributable, at least to platforms with
the same OS and CPU.  Read the README file of the freeze program for more
disclaimers.</p>
<p>You can use freeze on Windows, but you must download the source tree (see
<a class="reference external" href="http://www.python.org/download/source">http://www.python.org/download/source</a>).  The freeze program is in the
<tt class="docutils literal"><span class="pre">Tools\freeze</span></tt> subdirectory of the source tree.</p>
<p>You need the Microsoft VC++ compiler, and you probably need to build Python.
The required project files are in the PCbuild directory.</p>
</div>
<div class="section" id="is-a-pyd-file-the-same-as-a-dll">
<h2><a class="toc-backref" href="#id6">Is a <tt class="docutils literal"><span class="pre">*.pyd</span></tt> file the same as a DLL?</a><a class="headerlink" href="#is-a-pyd-file-the-same-as-a-dll" title="Permalink to this headline">¶</a></h2>
<p>Yes, .pyd files are dll&#8217;s, but there are a few differences.  If you have a DLL
named <tt class="docutils literal"><span class="pre">foo.pyd</span></tt>, then it must have a function <tt class="docutils literal"><span class="pre">initfoo()</span></tt>.  You can then
write Python &#8220;import foo&#8221;, and Python will search for foo.pyd (as well as
foo.py, foo.pyc) and if it finds it, will attempt to call <tt class="docutils literal"><span class="pre">initfoo()</span></tt> to
initialize it.  You do not link your .exe with foo.lib, as that would cause
Windows to require the DLL to be present.</p>
<p>Note that the search path for foo.pyd is PYTHONPATH, not the same as the path
that Windows uses to search for foo.dll.  Also, foo.pyd need not be present to
run your program, whereas if you linked your program with a dll, the dll is
required.  Of course, foo.pyd is required if you want to say <tt class="docutils literal"><span class="pre">import</span> <span class="pre">foo</span></tt>.  In
a DLL, linkage is declared in the source code with <tt class="docutils literal"><span class="pre">__declspec(dllexport)</span></tt>.
In a .pyd, linkage is defined in a list of available functions.</p>
</div>
<div class="section" id="how-can-i-embed-python-into-a-windows-application">
<h2><a class="toc-backref" href="#id7">How can I embed Python into a Windows application?</a><a class="headerlink" href="#how-can-i-embed-python-into-a-windows-application" title="Permalink to this headline">¶</a></h2>
<p>Embedding the Python interpreter in a Windows app can be summarized as follows:</p>
<ol class="arabic">
<li><p class="first">Do _not_ build Python into your .exe file directly.  On Windows, Python must
be a DLL to handle importing modules that are themselves DLL&#8217;s.  (This is the
first key undocumented fact.)  Instead, link to <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></tt>; it is
typically installed in <tt class="docutils literal"><span class="pre">C:\Windows\System</span></tt>.  <em>NN</em> is the Python version, a
number such as &#8220;23&#8221; for Python 2.3.</p>
<p>You can link to Python in two different ways.  Load-time linking means
linking against <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></tt>, while run-time linking means linking
against <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></tt>.  (General note: <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></tt> is the
so-called &#8220;import lib&#8221; corresponding to <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></tt>.  It merely
defines symbols for the linker.)</p>
<p>Run-time linking greatly simplifies link options; everything happens at run
time.  Your code must load <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></tt> using the Windows
<tt class="docutils literal"><span class="pre">LoadLibraryEx()</span></tt> routine.  The code must also use access routines and data
in <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></tt> (that is, Python&#8217;s C API&#8217;s) using pointers obtained
by the Windows <tt class="docutils literal"><span class="pre">GetProcAddress()</span></tt> routine.  Macros can make using these
pointers transparent to any C code that calls routines in Python&#8217;s C API.</p>
<p>Borland note: convert <tt class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></tt> to OMF format using Coff2Omf.exe
first.</p>
</li>
<li><p class="first">If you use SWIG, it is easy to create a Python &#8220;extension module&#8221; that will
make the app&#8217;s data and methods available to Python.  SWIG will handle just
about all the grungy details for you.  The result is C code that you link
<em>into</em> your .exe file (!)  You do _not_ have to create a DLL file, and this
also simplifies linking.</p>
</li>
<li><p class="first">SWIG will create an init function (a C function) whose name depends on the
name of the extension module.  For example, if the name of the module is leo,
the init function will be called initleo().  If you use SWIG shadow classes,
as you should, the init function will be called initleoc().  This initializes
a mostly hidden helper class used by the shadow class.</p>
<p>The reason you can link the C code in step 2 into your .exe file is that
calling the initialization function is equivalent to importing the module
into Python! (This is the second key undocumented fact.)</p>
</li>
<li><p class="first">In short, you can use the following code to initialize the Python interpreter
with your extension module.</p>
<div class="highlight-c"><div class="highlight"><pre><span class="cp">#include &quot;python.h&quot;</span>
<span class="p">...</span>
<span class="n">Py_Initialize</span><span class="p">();</span>  <span class="c1">// Initialize Python.</span>
<span class="n">initmyAppc</span><span class="p">();</span>  <span class="c1">// Initialize (import) the helper class.</span>
<span class="n">PyRun_SimpleString</span><span class="p">(</span><span class="s">&quot;import myApp&quot;</span><span class="p">)</span> <span class="p">;</span>  <span class="c1">// Import the shadow class.</span>
</pre></div>
</div>
</li>
<li><p class="first">There are two problems with Python&#8217;s C API which will become apparent if you
use a compiler other than MSVC, the compiler used to build pythonNN.dll.</p>
<p>Problem 1: The so-called &#8220;Very High Level&#8221; functions that take FILE *
arguments will not work in a multi-compiler environment because each
compiler&#8217;s notion of a struct FILE will be different.  From an implementation
standpoint these are very _low_ level functions.</p>
<p>Problem 2: SWIG generates the following code when generating wrappers to void
functions:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="n">Py_INCREF</span><span class="p">(</span><span class="n">Py_None</span><span class="p">);</span>
<span class="n">_resultobj</span> <span class="o">=</span> <span class="n">Py_None</span><span class="p">;</span>
<span class="k">return</span> <span class="n">_resultobj</span><span class="p">;</span>
</pre></div>
</div>
<p>Alas, Py_None is a macro that expands to a reference to a complex data
structure called _Py_NoneStruct inside pythonNN.dll.  Again, this code will
fail in a mult-compiler environment.  Replace such code by:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="k">return</span> <span class="n">Py_BuildValue</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>It may be possible to use SWIG&#8217;s <tt class="docutils literal"><span class="pre">%typemap</span></tt> command to make the change
automatically, though I have not been able to get this to work (I&#8217;m a
complete SWIG newbie).</p>
</li>
<li><p class="first">Using a Python shell script to put up a Python interpreter window from inside
your Windows app is not a good idea; the resulting window will be independent
of your app&#8217;s windowing system.  Rather, you (or the wxPythonWindow class)
should create a &#8220;native&#8221; interpreter window.  It is easy to connect that
window to the Python interpreter.  You can redirect Python&#8217;s i/o to _any_
object that supports read and write, so all you need is a Python object
(defined in your extension module) that contains read() and write() methods.</p>
</li>
</ol>
</div>
<div class="section" id="how-do-i-use-python-for-cgi">
<h2><a class="toc-backref" href="#id8">How do I use Python for CGI?</a><a class="headerlink" href="#how-do-i-use-python-for-cgi" title="Permalink to this headline">¶</a></h2>
<p>On the Microsoft IIS server or on the Win95 MS Personal Web Server you set up
Python in the same way that you would set up any other scripting engine.</p>
<p>Run regedt32 and go to:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">HKEY_LOCAL_MACHINE</span>\<span class="n">SYSTEM</span>\<span class="n">CurrentControlSet</span>\<span class="n">Services</span>\<span class="n">W3SVC</span>\<span class="n">Parameters</span>\<span class="n">ScriptMap</span>
</pre></div>
</div>
<p>and enter the following line (making any specific changes that your system may
need):</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="o">.</span><span class="n">py</span> <span class="p">:</span><span class="n">REG_SZ</span><span class="p">:</span> <span class="n">c</span><span class="p">:</span>\<span class="o">&lt;</span><span class="n">path</span> <span class="n">to</span> <span class="n">python</span><span class="o">&gt;</span>\<span class="n">python</span><span class="o">.</span><span class="n">exe</span> <span class="o">-</span><span class="n">u</span> <span class="o">%</span><span class="n">s</span> <span class="o">%</span><span class="n">s</span>
</pre></div>
</div>
<p>This line will allow you to call your script with a simple reference like:
<tt class="docutils literal"><span class="pre">http://yourserver/scripts/yourscript.py</span></tt> provided &#8220;scripts&#8221; is an
&#8220;executable&#8221; directory for your server (which it usually is by default).  The
<a class="reference internal" href="../using/cmdline.html#cmdoption-u"><em class="xref std std-option">-u</em></a> flag specifies unbuffered and binary mode for stdin - needed when
working with binary data.</p>
<p>In addition, it is recommended that using &#8221;.py&#8221; may not be a good idea for the
file extensions when used in this context (you might want to reserve <tt class="docutils literal"><span class="pre">*.py</span></tt>
for support modules and use <tt class="docutils literal"><span class="pre">*.cgi</span></tt> or <tt class="docutils literal"><span class="pre">*.cgp</span></tt> for &#8220;main program&#8221; scripts).</p>
<p>In order to set up Internet Information Services 5 to use Python for CGI
processing, please see the following links:</p>
<blockquote>
<div><a class="reference external" href="http://www.e-coli.net/pyiis_server.html">http://www.e-coli.net/pyiis_server.html</a> (for Win2k Server)
<a class="reference external" href="http://www.e-coli.net/pyiis.html">http://www.e-coli.net/pyiis.html</a> (for Win2k pro)</div></blockquote>
<p>Configuring Apache is much simpler.  In the Apache configuration file
<tt class="docutils literal"><span class="pre">httpd.conf</span></tt>, add the following line at the end of the file:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">ScriptInterpreterSource</span> <span class="n">Registry</span>
</pre></div>
</div>
<p>Then, give your Python CGI-scripts the extension .py and put them in the cgi-bin
directory.</p>
</div>
<div class="section" id="how-do-i-keep-editors-from-inserting-tabs-into-my-python-source">
<h2><a class="toc-backref" href="#id9">How do I keep editors from inserting tabs into my Python source?</a><a class="headerlink" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source" title="Permalink to this headline">¶</a></h2>
<p>The FAQ does not recommend using tabs, and the Python style guide, <span class="target" id="index-0"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0008"><strong>PEP 8</strong></a>,
recommends 4 spaces for distributed Python code; this is also the Emacs
python-mode default.</p>
<p>Under any editor, mixing tabs and spaces is a bad idea.  MSVC is no different in
this respect, and is easily configured to use spaces: Take <em class="menuselection">Tools
‣ Options ‣ Tabs</em>, and for file type &#8220;Default&#8221; set &#8220;Tab size&#8221; and &#8220;Indent
size&#8221; to 4, and select the &#8220;Insert spaces&#8221; radio button.</p>
<p>If you suspect mixed tabs and spaces are causing problems in leading whitespace,
run Python with the <em class="xref std std-option">-t</em> switch or run <tt class="docutils literal"><span class="pre">Tools/Scripts/tabnanny.py</span></tt> to
check a directory tree in batch mode.</p>
</div>
<div class="section" id="how-do-i-check-for-a-keypress-without-blocking">
<h2><a class="toc-backref" href="#id10">How do I check for a keypress without blocking?</a><a class="headerlink" href="#how-do-i-check-for-a-keypress-without-blocking" title="Permalink to this headline">¶</a></h2>
<p>Use the msvcrt module.  This is a standard Windows-specific extension module.
It defines a function <tt class="docutils literal"><span class="pre">kbhit()</span></tt> which checks whether a keyboard hit is
present, and <tt class="docutils literal"><span class="pre">getch()</span></tt> which gets one character without echoing it.</p>
</div>
<div class="section" id="how-do-i-emulate-os-kill-in-windows">
<h2><a class="toc-backref" href="#id11">How do I emulate os.kill() in Windows?</a><a class="headerlink" href="#how-do-i-emulate-os-kill-in-windows" title="Permalink to this headline">¶</a></h2>
<p>Prior to Python 2.7 and 3.2, to terminate a process, you can use <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><tt class="xref py py-mod docutils literal"><span class="pre">ctypes</span></tt></a>:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">ctypes</span>

<span class="k">def</span> <span class="nf">kill</span><span class="p">(</span><span class="n">pid</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;kill function for Win32&quot;&quot;&quot;</span>
    <span class="n">kernel32</span> <span class="o">=</span> <span class="n">ctypes</span><span class="o">.</span><span class="n">windll</span><span class="o">.</span><span class="n">kernel32</span>
    <span class="n">handle</span> <span class="o">=</span> <span class="n">kernel32</span><span class="o">.</span><span class="n">OpenProcess</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pid</span><span class="p">)</span>
    <span class="k">return</span> <span class="p">(</span><span class="mi">0</span> <span class="o">!=</span> <span class="n">kernel32</span><span class="o">.</span><span class="n">TerminateProcess</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
</pre></div>
</div>
<p>In 2.7 and 3.2, <a class="reference internal" href="../library/os.html#os.kill" title="os.kill"><tt class="xref py py-func docutils literal"><span class="pre">os.kill()</span></tt></a> is implemented similar to the above function,
with the additional feature of being able to send CTRL+C and CTRL+BREAK
to console subprocesses which are designed to handle those signals. See
<a class="reference internal" href="../library/os.html#os.kill" title="os.kill"><tt class="xref py py-func docutils literal"><span class="pre">os.kill()</span></tt></a> for further details.</p>
</div>
<div class="section" id="why-does-os-path-isdir-fail-on-nt-shared-directories">
<h2><a class="toc-backref" href="#id12">Why does os.path.isdir() fail on NT shared directories?</a><a class="headerlink" href="#why-does-os-path-isdir-fail-on-nt-shared-directories" title="Permalink to this headline">¶</a></h2>
<p>The solution appears to be always append the &#8220;\&#8221; on the end of shared
drives.</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span> <span class="s">&#39;</span><span class="se">\\\\</span><span class="s">rorschach</span><span class="se">\\</span><span class="s">public&#39;</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span> <span class="s">&#39;</span><span class="se">\\\\</span><span class="s">rorschach</span><span class="se">\\</span><span class="s">public</span><span class="se">\\</span><span class="s">&#39;</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<p>It helps to think of share points as being like drive letters.  Example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">k</span><span class="p">:</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">a</span> <span class="n">directory</span>
<span class="n">k</span><span class="p">:</span>\ <span class="ow">is</span> <span class="n">a</span> <span class="n">directory</span>
<span class="n">k</span><span class="p">:</span>\<span class="n">media</span> <span class="ow">is</span> <span class="n">a</span> <span class="n">directory</span>
<span class="n">k</span><span class="p">:</span>\<span class="n">media</span>\ <span class="ow">is</span> <span class="ow">not</span> <span class="n">a</span> <span class="n">directory</span>
</pre></div>
</div>
<p>The same rules apply if you substitute &#8220;k:&#8221; with &#8220;\conkyfoo&#8221;:</p>
<div class="highlight-python3"><div class="highlight"><pre>\\<span class="n">conky</span>\<span class="n">foo</span>  <span class="ow">is</span> <span class="ow">not</span> <span class="n">a</span> <span class="n">directory</span>
\\<span class="n">conky</span>\<span class="n">foo</span>\ <span class="ow">is</span> <span class="n">a</span> <span class="n">directory</span>
\\<span class="n">conky</span>\<span class="n">foo</span>\<span class="n">media</span> <span class="ow">is</span> <span class="n">a</span> <span class="n">directory</span>
\\<span class="n">conky</span>\<span class="n">foo</span>\<span class="n">media</span>\ <span class="ow">is</span> <span class="ow">not</span> <span class="n">a</span> <span class="n">directory</span>
</pre></div>
</div>
</div>
<div class="section" id="cgi-py-or-other-cgi-programming-doesn-t-work-sometimes-on-nt-or-win95">
<h2><a class="toc-backref" href="#id13">cgi.py (or other CGI programming) doesn&#8217;t work sometimes on NT or win95!</a><a class="headerlink" href="#cgi-py-or-other-cgi-programming-doesn-t-work-sometimes-on-nt-or-win95" title="Permalink to this headline">¶</a></h2>
<p>Be sure you have the latest python.exe, that you are using python.exe rather
than a GUI version of Python and that you have configured the server to execute</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="s">&quot;...\python.exe -u ...&quot;</span>
</pre></div>
</div>
<p>for the CGI execution.  The <a class="reference internal" href="../using/cmdline.html#cmdoption-u"><em class="xref std std-option">-u</em></a> (unbuffered) option on NT and Win95
prevents the interpreter from altering newlines in the standard input and
output.  Without it post/multipart requests will seem to have the wrong length
and binary (e.g. GIF) responses may get garbled (resulting in broken images, PDF
files, and other binary downloads failing).</p>
</div>
<div class="section" id="why-doesn-t-os-popen-work-in-pythonwin-on-nt">
<h2><a class="toc-backref" href="#id14">Why doesn&#8217;t os.popen() work in PythonWin on NT?</a><a class="headerlink" href="#why-doesn-t-os-popen-work-in-pythonwin-on-nt" title="Permalink to this headline">¶</a></h2>
<p>The reason that os.popen() doesn&#8217;t work from within PythonWin is due to a bug in
Microsoft&#8217;s C Runtime Library (CRT). The CRT assumes you have a Win32 console
attached to the process.</p>
<p>You should use the win32pipe module&#8217;s popen() instead which doesn&#8217;t depend on
having an attached Win32 console.</p>
<p>Example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">win32pipe</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">win32pipe</span><span class="o">.</span><span class="n">popen</span><span class="p">(</span><span class="s">&#39;dir /c c:</span><span class="se">\\</span><span class="s">&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">())</span>
<span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="why-doesn-t-os-popen-win32pipe-popen-work-on-win9x">
<h2><a class="toc-backref" href="#id15">Why doesn&#8217;t os.popen()/win32pipe.popen() work on Win9x?</a><a class="headerlink" href="#why-doesn-t-os-popen-win32pipe-popen-work-on-win9x" title="Permalink to this headline">¶</a></h2>
<p>There is a bug in Win9x that prevents os.popen/win32pipe.popen* from
working. The good news is there is a way to work around this problem.  The
Microsoft Knowledge Base article that you need to lookup is: Q150956. You will
find links to the knowledge base at: <a class="reference external" href="http://support.microsoft.com/">http://support.microsoft.com/</a>.</p>
</div>
<div class="section" id="pyrun-simplefile-crashes-on-windows-but-not-on-unix-why">
<h2><a class="toc-backref" href="#id16">PyRun_SimpleFile() crashes on Windows but not on Unix; why?</a><a class="headerlink" href="#pyrun-simplefile-crashes-on-windows-but-not-on-unix-why" title="Permalink to this headline">¶</a></h2>
<p>This is very sensitive to the compiler vendor, version and (perhaps) even
options.  If the FILE* structure in your embedding program isn&#8217;t the same as is
assumed by the Python interpreter it won&#8217;t work.</p>
<p>The Python 1.5.* DLLs (<tt class="docutils literal"><span class="pre">python15.dll</span></tt>) are all compiled with MS VC++ 5.0 and
with multithreading-DLL options (<tt class="docutils literal"><span class="pre">/MD</span></tt>).</p>
<p>If you can&#8217;t change compilers or flags, try using <tt class="xref c c-func docutils literal"><span class="pre">Py_RunSimpleString()</span></tt>.
A trick to get it to run an arbitrary file is to construct a call to
<a class="reference internal" href="../library/functions.html#exec" title="exec"><tt class="xref py py-func docutils literal"><span class="pre">exec()</span></tt></a> and <a class="reference internal" href="../library/functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> with the name of your file as argument.</p>
<p>Also note that you can not mix-and-match Debug and Release versions.  If you
wish to use the Debug Multithreaded DLL, then your module <em>must</em> have <tt class="docutils literal"><span class="pre">_d</span></tt>
appended to the base name.</p>
</div>
<div class="section" id="importing-tkinter-fails-on-windows-95-98-why">
<h2><a class="toc-backref" href="#id17">Importing _tkinter fails on Windows 95/98: why?</a><a class="headerlink" href="#importing-tkinter-fails-on-windows-95-98-why" title="Permalink to this headline">¶</a></h2>
<p>Sometimes, the import of _tkinter fails on Windows 95 or 98, complaining with a
message like the following:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="ne">ImportError</span><span class="p">:</span> <span class="n">DLL</span> <span class="n">load</span> <span class="n">failed</span><span class="p">:</span> <span class="n">One</span> <span class="n">of</span> <span class="n">the</span> <span class="n">library</span> <span class="n">files</span> <span class="n">needed</span>
<span class="n">to</span> <span class="n">run</span> <span class="n">this</span> <span class="n">application</span> <span class="n">cannot</span> <span class="n">be</span> <span class="n">found</span><span class="o">.</span>
</pre></div>
</div>
<p>It could be that you haven&#8217;t installed Tcl/Tk, but if you did install Tcl/Tk,
and the Wish application works correctly, the problem may be that its installer
didn&#8217;t manage to edit the autoexec.bat file correctly.  It tries to add a
statement that changes the PATH environment variable to include the Tcl/Tk &#8216;bin&#8217;
subdirectory, but sometimes this edit doesn&#8217;t quite work.  Opening it with
notepad usually reveals what the problem is.</p>
<p>(One additional hint, noted by David Szafranski: you can&#8217;t use long filenames
here; e.g. use <tt class="docutils literal"><span class="pre">C:\PROGRA~1\Tcl\bin</span></tt> instead of <tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\Tcl\bin</span></tt>.)</p>
</div>
<div class="section" id="how-do-i-extract-the-downloaded-documentation-on-windows">
<h2><a class="toc-backref" href="#id18">How do I extract the downloaded documentation on Windows?</a><a class="headerlink" href="#how-do-i-extract-the-downloaded-documentation-on-windows" title="Permalink to this headline">¶</a></h2>
<p>Sometimes, when you download the documentation package to a Windows machine
using a web browser, the file extension of the saved file ends up being .EXE.
This is a mistake; the extension should be .TGZ.</p>
<p>Simply rename the downloaded file to have the .TGZ extension, and WinZip will be
able to handle it.  (If your copy of WinZip doesn&#8217;t, get a newer one from
<a class="reference external" href="http://www.winzip.com">http://www.winzip.com</a>.)</p>
</div>
<div class="section" id="missing-cw3215mt-dll-or-missing-cw3215-dll">
<h2><a class="toc-backref" href="#id19">Missing cw3215mt.dll (or missing cw3215.dll)</a><a class="headerlink" href="#missing-cw3215mt-dll-or-missing-cw3215-dll" title="Permalink to this headline">¶</a></h2>
<p>Sometimes, when using Tkinter on Windows, you get an error that cw3215mt.dll or
cw3215.dll is missing.</p>
<p>Cause: you have an old Tcl/Tk DLL built with cygwin in your path (probably
<tt class="docutils literal"><span class="pre">C:\Windows</span></tt>).  You must use the Tcl/Tk DLLs from the standard Tcl/Tk
installation (Python 1.5.2 comes with one).</p>
</div>
<div class="section" id="warning-about-ctl3d32-version-from-installer">
<h2><a class="toc-backref" href="#id20">Warning about CTL3D32 version from installer</a><a class="headerlink" href="#warning-about-ctl3d32-version-from-installer" title="Permalink to this headline">¶</a></h2>
<p>The Python installer issues a warning like this:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">This</span> <span class="n">version</span> <span class="n">uses</span> <span class="n">CTL3D32</span><span class="o">.</span><span class="n">DLL</span> <span class="n">which</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">the</span> <span class="n">correct</span> <span class="n">version</span><span class="o">.</span>
<span class="n">This</span> <span class="n">version</span> <span class="ow">is</span> <span class="n">used</span> <span class="k">for</span> <span class="n">windows</span> <span class="n">NT</span> <span class="n">applications</span> <span class="n">only</span><span class="o">.</span>
</pre></div>
</div>
<p>Tim Peters:</p>
<blockquote>
<div>This is a Microsoft DLL, and a notorious source of problems.  The message
means what it says: you have the wrong version of this DLL for your operating
system.  The Python installation did not cause this &#8211; something else you
installed previous to this overwrote the DLL that came with your OS (probably
older shareware of some sort, but there&#8217;s no way to tell now).  If you search
for &#8220;CTL3D32&#8221; using any search engine (AltaVista, for example), you&#8217;ll find
hundreds and hundreds of web pages complaining about the same problem with
all sorts of installation programs.  They&#8217;ll point you to ways to get the
correct version reinstalled on your system (since Python doesn&#8217;t cause this,
we can&#8217;t fix it).</div></blockquote>
<p>David A Burton has written a little program to fix this.  Go to
<a class="reference external" href="http://www.burtonsys.com/downloads.html">http://www.burtonsys.com/downloads.html</a> and click on &#8220;ctl3dfix.zip&#8221;.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Python on Windows FAQ</a><ul>
<li><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows">How do I run a Python program under Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-make-python-scripts-executable">How do I make Python scripts executable?</a></li>
<li><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start">Why does Python sometimes take so long to start?</a></li>
<li><a class="reference internal" href="#where-is-freeze-for-windows">Where is Freeze for Windows?</a></li>
<li><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll">Is a <tt class="docutils literal"><span class="pre">*.pyd</span></tt> file the same as a DLL?</a></li>
<li><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application">How can I embed Python into a Windows application?</a></li>
<li><a class="reference internal" href="#how-do-i-use-python-for-cgi">How do I use Python for CGI?</a></li>
<li><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source">How do I keep editors from inserting tabs into my Python source?</a></li>
<li><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking">How do I check for a keypress without blocking?</a></li>
<li><a class="reference internal" href="#how-do-i-emulate-os-kill-in-windows">How do I emulate os.kill() in Windows?</a></li>
<li><a class="reference internal" href="#why-does-os-path-isdir-fail-on-nt-shared-directories">Why does os.path.isdir() fail on NT shared directories?</a></li>
<li><a class="reference internal" href="#cgi-py-or-other-cgi-programming-doesn-t-work-sometimes-on-nt-or-win95">cgi.py (or other CGI programming) doesn&#8217;t work sometimes on NT or win95!</a></li>
<li><a class="reference internal" href="#why-doesn-t-os-popen-work-in-pythonwin-on-nt">Why doesn&#8217;t os.popen() work in PythonWin on NT?</a></li>
<li><a class="reference internal" href="#why-doesn-t-os-popen-win32pipe-popen-work-on-win9x">Why doesn&#8217;t os.popen()/win32pipe.popen() work on Win9x?</a></li>
<li><a class="reference internal" href="#pyrun-simplefile-crashes-on-windows-but-not-on-unix-why">PyRun_SimpleFile() crashes on Windows but not on Unix; why?</a></li>
<li><a class="reference internal" href="#importing-tkinter-fails-on-windows-95-98-why">Importing _tkinter fails on Windows 95/98: why?</a></li>
<li><a class="reference internal" href="#how-do-i-extract-the-downloaded-documentation-on-windows">How do I extract the downloaded documentation on Windows?</a></li>
<li><a class="reference internal" href="#missing-cw3215mt-dll-or-missing-cw3215-dll">Missing cw3215mt.dll (or missing cw3215.dll)</a></li>
<li><a class="reference internal" href="#warning-about-ctl3d32-version-from-installer">Warning about CTL3D32 version from installer</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="extending.html"
                        title="previous chapter">Extending/Embedding FAQ</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="gui.html"
                        title="next chapter">Graphic User Interface FAQ</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/faq/windows.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="gui.html" title="Graphic User Interface FAQ"
             >next</a> |</li>
        <li class="right" >
          <a href="extending.html" title="Extending/Embedding FAQ"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >Python Frequently Asked Questions</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2011, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Sep 04, 2011.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>

  </body>
</html>