diff -r 0238cc842805 Doc/faq/windows.rst --- a/Doc/faq/windows.rst Thu Dec 06 17:49:58 2012 -0500 +++ b/Doc/faq/windows.rst Fri Dec 07 23:37:29 2012 +0530 @@ -9,7 +9,7 @@ .. contents:: .. XXX need review for Python 3. - XXX need review for Windows Vista/Seven? + XXX need additional FAQ questions. How do I run a Python program under Windows? @@ -17,9 +17,7 @@ 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. +obvious; otherwise, you might need a little more guidance. .. sidebar:: |Python Development on XP|_ :subtitle: `Python Development on XP`_ @@ -36,12 +34,12 @@ Unless you use some sort of integrated development environment, you will end up *typing* Windows commands into what is variously referred to as a "DOS window" or "Command prompt window". Usually you can create such a window from your -Start menu; under Windows 2000 the menu selection is :menuselection:`Start --> +Start menu; under Windows 7 the menu selection is :menuselection:`Start --> Programs --> Accessories --> Command Prompt`. You should be able to recognize when you have started such a window because you will see a Windows "command prompt", which usually looks like this:: - C:\> + C:\Users\Asis> The letter may be different, and there might be other things after it, so you might just as easily see something like:: @@ -53,16 +51,21 @@ running Python programs. You need to realize that your Python scripts have to be processed by another -program called the Python interpreter. The interpreter reads your script, +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? First, you need to make sure that your command window recognises the word "python" as an instruction to start the interpreter. If you have opened a command window, you should try entering the command ``python`` and hitting -return. You should then see something like:: +return. - Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 + C:\Users\Asis> python + +You should then see something like:: + + Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] + on win32 Type "help", "copyright", "credits" or "license" for more information. >>> @@ -82,7 +85,7 @@ Windows command prompt. You may also find that you have a Start-menu entry such as :menuselection:`Start ---> Programs --> Python 2.2 --> Python (command line)` that results in you +--> Programs --> Python 2.7 --> Python (command line)` that results in you seeing the ``>>>`` prompt in a new window. If so, the window will disappear after you enter the Ctrl-Z character; Windows is running a single "python" command in the window, and closes it when you terminate the interpreter. @@ -120,25 +123,32 @@ dir C:\py* will probably tell you where it is installed; the usual location is something -like ``C:\Python23``. Otherwise you will be reduced to a search of your whole +like ``C:\Python27``. Otherwise you will be reduced to a search of your whole disk ... use :menuselection:`Tools --> Find` or hit the :guilabel:`Search` button and look for "python.exe". Supposing you discover that Python is -installed in the ``C:\Python23`` directory (the default at the time of writing), +installed in the ``C:\Python27`` directory (the default at the time of writing), you should make sure that entering the command :: - c:\Python23\python + c:\Python27\python starts up the interpreter as above (and don't forget you'll need a "CTRL-Z" and an "Enter" 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 ``C:\AUTOEXEC.BAT`` -file. You would want to add a line like the following to ``AUTOEXEC.BAT``:: +add it to the start-up routines your computer goes through. In order to run +programs, your operating system looks in various places, and tries to match the +name of the program / command you typed with some programs along the way. +Goto: - PATH C:\Python23;%PATH% + Control Panel > System > Advanced System Settings> |Environmental Variables| + > System variables -> Path -For Windows NT, 2000 and (I assume) XP, you will need to add a string such as :: +This needs to include: C:\Python27; (or equivalent). Click 'Edit' button to add. +If you put it at the front, it will be the first place looked. You can also add +it at the end, which is possibly saner. Then restart your prompt, and try +typing 'python'. If it all worked, you should get a ">>>" prompt. - ;C:\Python23 +For Windows XP, you will need to add a string such as :: + + ;C:\Python27 to the current setting for the PATH environment variable, which you will find in the properties window of "My Computer" under the "Advanced" tab. Note that if @@ -148,9 +158,7 @@ If you aren'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't need to reboot for Windows NT, XP -or 2000. You can also avoid it in earlier versions by editing the file -``C:\WINDOWS\COMMAND\CMDINIT.BAT`` instead of ``AUTOEXEC.BAT``. +setting has taken effect. You should now be able to start a new command window, enter ``python`` at the ``C:\>`` (or whatever) prompt, and see the ``>>>`` prompt that indicates the @@ -172,13 +180,10 @@ if you hadn't wanted to change your current directory. -Under NT, 2000 and XP you may well find that the installation process has also -arranged that the command ``pytest.py`` (or, if the file isn't in the current -directory, ``C:\Steve\Projects\Python\pytest.py``) will automatically recognize -the ".py" extension and run the Python interpreter on the named file. Using this -feature is fine, but *some* versions of Windows have bugs which mean that this -form isn't exactly equivalent to using the interpreter explicitly, so be -careful. +Under XP you may well find that the installation process has also arranged that +the command ``pytest.py`` (or, if the file isn't in the current directory, +``C:\Steve\Projects\Python\pytest.py``) will automatically recognize the +".py" extension and run the Python interpreter on the named file. The important things to remember are: @@ -211,23 +216,13 @@ How do I make Python scripts executable? ---------------------------------------- -On Windows 2000, the standard Python installer already associates the .py +On Windows, 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 (``D:\Program Files\Python\python.exe "%1" %*``). This is enough to make scripts executable from the command prompt as 'foo.py'. If you'd rather be able to execute the script by simple typing 'foo' with no extension you need to add .py to the PATHEXT environment variable. -On Windows NT, the steps taken by the installer as described above allow you to -run a script with 'foo.py', 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. - -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:: - - @setlocal enableextensions & python -x %~f0 %* & goto :EOF - Why does Python sometimes take so long to start? ------------------------------------------------ @@ -246,21 +241,25 @@ offender. -Where is Freeze for Windows? ----------------------------- +How do I make an .exe from .py? +------------------------------- -"Freeze" is a program that allows you to ship a Python program as a single -stand-alone executable file. It is *not* a compiler; your programs don'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. +'py2exe' is a Python Distutils extension which converts Python scripts into +executable Windows programs, able to run without requiring Python installation. +You can download the py2exe module from - +http://sourceforge.net/project/showfiles.php?group_id=15583 +There is a tutorial for converting to exe by py2exe on - +http://www.py2exe.org/index.cgi/Tutorial -You can use freeze on Windows, but you must download the source tree (see -http://www.python.org/download/source). The freeze program is in the -``Tools\freeze`` subdirectory of the source tree. +PyInstaller is a program that converts (packages) Python programs into +stand-alone executables. All the required tricks to make external packages work +are already integrated within PyInstaller itself so that there is no user +intervention required. More info - http://www.pyinstaller.org/ -You need the Microsoft VC++ compiler, and you probably need to build Python. -The required project files are in the PCbuild directory. +Several other modules & options also exist for doing the conversion. +The main advantage of this conversion is that you can redistribute your +application without python. The end user needn't install python on his machine. +You can make your application closed source (unfortunate) etc. Is a ``*.pyd`` file the same as a DLL? @@ -292,7 +291,7 @@ be a DLL to handle importing modules that are themselves DLL's. (This is the first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is typically installed in ``C:\Windows\System``. *NN* is the Python version, a - number such as "23" for Python 2.3. + number such as "27" for Python 2.7. You can link to Python in two different ways. Load-time linking means linking against :file:`python{NN}.lib`, while run-time linking means linking @@ -459,160 +458,3 @@ 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 :func:`os.kill` for further details. - - -Why does os.path.isdir() fail on NT shared directories? -------------------------------------------------------- - -In order to work correctly, :func:`os.path.isdir` requires a ``"\\"`` at the -end of the shared drive:: - - >>> import os - >>> os.path.isdir('\\\\rorschach\\public') - 0 - >>> os.path.isdir('\\\\rorschach\\public\\') - 1 - -It helps to think of share points as being like drive letters. Example:: - - k: is not a directory - k:\ is a directory - k:\media is a directory - k:\media\ is not a directory - -The same rules apply if you substitute ``"k:"`` with ``"\\conky\foo"``:: - - \\conky\foo is not a directory - \\conky\foo\ is a directory - \\conky\foo\media is a directory - \\conky\foo\media\ is not a directory - - -cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! ------------------------------------------------------------------------- - -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 -:: - - "...\python.exe -u ..." - -for the CGI execution. The :option:`-u` (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). - - -Why doesn't os.popen() work in PythonWin on NT? ------------------------------------------------ - -The reason that os.popen() doesn't work from within PythonWin is due to a bug in -Microsoft's C Runtime Library (CRT). The CRT assumes you have a Win32 console -attached to the process. - -You should use the win32pipe module's popen() instead which doesn't depend on -having an attached Win32 console. - -Example:: - - import win32pipe - f = win32pipe.popen('dir /c c:\\') - print(f.readlines()) - f.close() - - -Why doesn't os.popen()/win32pipe.popen() work on Win9x? -------------------------------------------------------- - -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: http://support.microsoft.com/. - - -PyRun_SimpleFile() crashes on Windows but not on Unix; why? ------------------------------------------------------------ - -This is very sensitive to the compiler vendor, version and (perhaps) even -options. If the FILE* structure in your embedding program isn't the same as is -assumed by the Python interpreter it won't work. - -The Python 1.5.* DLLs (``python15.dll``) are all compiled with MS VC++ 5.0 and -with multithreading-DLL options (``/MD``). - -If you can't change compilers or flags, try using :c:func:`Py_RunSimpleString`. -A trick to get it to run an arbitrary file is to construct a call to -:func:`exec` and :func:`open` with the name of your file as argument. - -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 *must* have ``_d`` -appended to the base name. - - -Importing _tkinter fails on Windows 95/98: why? ------------------------------------------------- - -Sometimes, the import of _tkinter fails on Windows 95 or 98, complaining with a -message like the following:: - - ImportError: DLL load failed: One of the library files needed - to run this application cannot be found. - -It could be that you haven'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'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 'bin' -subdirectory, but sometimes this edit doesn't quite work. Opening it with -notepad usually reveals what the problem is. - -(One additional hint, noted by David Szafranski: you can't use long filenames -here; e.g. use ``C:\PROGRA~1\Tcl\bin`` instead of ``C:\Program Files\Tcl\bin``.) - - -How do I extract the downloaded documentation on Windows? ---------------------------------------------------------- - -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. - -Simply rename the downloaded file to have the .TGZ extension, and WinZip will be -able to handle it. (If your copy of WinZip doesn't, get a newer one from -http://www.winzip.com.) - - -Missing cw3215mt.dll (or missing cw3215.dll) --------------------------------------------- - -Sometimes, when using Tkinter on Windows, you get an error that cw3215mt.dll or -cw3215.dll is missing. - -Cause: you have an old Tcl/Tk DLL built with cygwin in your path (probably -``C:\Windows``). You must use the Tcl/Tk DLLs from the standard Tcl/Tk -installation (Python 1.5.2 comes with one). - - -Warning about CTL3D32 version from installer --------------------------------------------- - -The Python installer issues a warning like this:: - - This version uses CTL3D32.DLL which is not the correct version. - This version is used for windows NT applications only. - -Tim Peters: - - 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 -- something else you - installed previous to this overwrote the DLL that came with your OS (probably - older shareware of some sort, but there's no way to tell now). If you search - for "CTL3D32" using any search engine (AltaVista, for example), you'll find - hundreds and hundreds of web pages complaining about the same problem with - all sorts of installation programs. They'll point you to ways to get the - correct version reinstalled on your system (since Python doesn't cause this, - we can't fix it). - -David A Burton has written a little program to fix this. Go to -http://www.burtonsys.com/downloads.html and click on "ctl3dfix.zip".