Python
Python
1
==========================
Copyright (c) 2001 Python Software Foundation.
All rights reserved.
Copyright (c) 2000 BeOpen.com.
All rights reserved.
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All rights reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum.
All rights reserved.
License information
-------------------
See the file "LICENSE" for information on the history of this
software, terms & conditions for usage, and a DISCLAIMER OF ALL
WARRANTIES.
This Python distribution contains no GNU General Public Licensed
(GPLed) code so it may be used in proprietary projects just like prior
Python distributions. There are interfaces to some GNU code but these
are entirely optional.
All trademarks referenced herein are property of their respective
holders.
Documentation
-------------
All documentation is provided online in a variety of formats. In
order of importance for new users: Tutorial, Library Reference,
Language Reference, Extending & Embedding, and the Python/C API. The
Library Reference is especially of immense value since much of
Python's power is described there, including the built-in data types
and functions!
All documentation is also available online at the Python web site
(http://www.python.org/doc/, see below). It is available online for
occasional reference, or can be downloaded in many formats for faster
access. The documentation is available in HTML, PostScript, PDF, and
LaTeX formats; the LaTeX version is primarily for documentation
authors, translators, and people with special formatting requirements.
Web sites
---------
New Python releases and related technologies are published at
http://www.python.org/. Come visit us!
There's also a Python community web site at http://starship.python.net/.
Bug reports
-----------
To report or search for bugs, please use the Python Bug
Tracker at http://sourceforge.net/bugs/?group_id=5470.
Questions
---------
For help, if you can't find it in the manuals or on the web site, it's
best to post to the comp.lang.python or the Python mailing list (see
above). If you specifically don't want to involve the newsgroup or
mailing list, send questions to help@python.org (a group of volunteers
who answer questions as they can). The newsgroup is the most
efficient way to ask public questions.
Build instructions
==================
Before you can build Python, you must first configure it. Fortunately,
the configuration and build process has been streamlined for most Unix
installations, so all you have to do is type a few commands,
optionally edit one file, and sit back. There are some platforms
where things are not quite as smooth; see the platform specific notes
below. If you want to build for multiple platforms sharing the same
source tree, see the section on VPATH below.
Start by running the script "./configure", which determines your system
configuration and creates the Makefile. (It takes a minute or two --
please be patient!) You may want to pass options to the configure
script or edit the Modules/Setup file after running configure -- see the
section below on configuration options and variables. When it's done,
you are ready to run make.
To build Python, you normally type "make" in the toplevel directory. If
you have changed the configuration or have modified Modules/Setup, the
Makefile may have to be rebuilt. In this case you may have to run make
again to correctly build your desired target. The interpreter
executable is built in the top level directory.
Once you have built a Python interpreter, see the subsections below on
testing, configuring additional modules, and installation. If you run
into trouble, see the next section. Editing the Modules/Setup file
after running make is supported; just run "make" again after making
the desired changes.
Troubleshooting
---------------
See also the platform specific notes in the next section.
If you run into other trouble, see section 3 of the FAQ
(http://www.python.org/cgi-bin/faqw.py or
http://www.python.org/doc/FAQ.html) for hints on what can go wrong,
and how to fix it.
If you rerun the configure script with different options, remove all
object files by running "make clean" before rebuilding. Believe it or
not, "make clean" sometimes helps to clean up other inexplicable
problems as well. Try it before sending in a bug report!
If the configure script fails or doesn't seem to find things that
should be there, inspect the config.log file. When you fix a
configure problem, be sure to remove config.cache!
If you get a warning for every file about the -Olimit option being no
longer supported, you can ignore it. There's no foolproof way to know
whether this option is needed; all we can do is test whether it is
accepted without error. On some systems, e.g. older SGI compilers, it
is essential for performance (specifically when compiling ceval.c,
which has more basic blocks than the default limit of 1000). If the
warning bothers you, edit the Makefile to remove "-Olimit 1500" from
the OPT variable.
If you get failures in test_long, or sys.maxint gets set to -1, you
are probably experiencing compiler bugs, usually related to
optimization. This is a common problem with some versions of gcc and
egcs, and some vendor-supplied compilers, which can sometimes be
worked around by turning off optimization. Consider switching to
stable versions (gcc 2.7.2.3, egcs 1.1.2, or contact your vendor.)
From Python 2.0 onward, all Python C code is ANSI C. Compiling using
old K&R-C-only compilers is no longer possible. ANSI C compilers are
available for all modern systems, either in the form of updated
compilers from the vendor, or one of the free compilers (gcc, egcs).
Platform specific notes
-----------------------
(Some of these may no longer apply. If you find you can build Python
on these platforms without the special directions mentioned here,
submit a documentation bug report to SourceForge (see Bug Reports
above) so we can remove them!)
64-bit platforms: The modules audioop, imageop and rgbimg don't work.
Don't try to enable them in the Modules/Setup file. They
contain code that is quite wordsize sensitive. (If you have a
fix, let us know!)
Solaris: When using Sun's C compiler with threads, at least on Solaris
2.5.1, you need to add the "-mt" compiler option (the simplest
way is probably to specify the compiler with this option as
the "CC" environment variable when running the configure
script).
Linux: A problem with threads and fork() was tracked down to a bug in
the pthreads code in glibc version 2.0.5; glibc version 2.0.7
solves the problem. This causes the popen2 test to fail;
problem and solution reported by Pablo Bleyer.
Under Linux systems using GNU libc 2 (aka libc6), the crypt
module now needs the -lcrypt option. Uncomment this flag in
Modules/Setup, or comment out the crypt module in the same
file. Most modern Linux systems use glibc2.
FreeBSD 3.x and probably platforms with NCurses that use libmytinfo or
similar: When using cursesmodule, the linking is not done in
the correct order with the defaults. Remove "-ltermcap" from
the readline entry in Setup, and use as curses entry: "curses
cursesmodule.c -lmytinfo -lncurses -ltermcap" - "mytinfo" (so
called on FreeBSD) should be the name of the auxiliary library
required on your platform. Normally, it would be linked
automatically, but not necessarily in the correct order.
BSDI: BSDI versions before 4.1 have known problems with threads,
which can cause strange errors in a number of modules (for
instance, the 'test_signal' test script will hang forever.)
Turning off threads (with --with-threads=no) or upgrading to
BSDI 4.1 solves this problem.
DEC Unix: Run configure with --with-dec-threads, or with
--with-threads=no if no threads are desired (threads are on by
default). When using GCC, it is possible to get an internal
compiler error if optimization is used. This was reported for
GCC 2.7.2.3 on selectmodule.c. Manually compile the affected
file without optimization to solve the problem.
DEC Ultrix: compile with GCC to avoid bugs in the native compiler,
and pass SHELL=/bin/sh5 to Make when installing.
AIX: A complete overhaul of the shared library support is now in
place. See Misc/AIX-NOTES for some notes on how it's done.
(The optimizer bug reported at this place in previous releases
has been worked around by a minimal code change.) If you get
errors about ptread_* functions, during compile or during
testing, try setting CC to a thread-safe (reentrant) compiler,
like "cc_r". For full C++ module support, set CC="xlC_r" (or
CC="xlC" without thread support).
HP-UX: Please read the file Misc/HPUX-NOTES for shared libraries.
When using threading, you may have to add -D_REENTRANT to the
OPT variable in the top-level Makefile; reported by Pat Knight,
this seems to make a difference (at least for HP-UX 10.20)
even though config.h defines it.
Minix: When using ack, use "CC=cc AR=aal RANLIB=: ./configure"!
SCO: The following apply to SCO 3 only; Python builds out of the box
on SCO 5 (or so we've heard).
1) Everything works much better if you add -U__STDC__ to the
defs. This is because all the SCO header files are broken.
Anything that isn't mentioned in the C standard is
conditionally excluded when __STDC__ is defined.
2) Due to the U.S. export restrictions, SCO broke the crypt
stuff out into a separate library, libcrypt_i.a so the LIBS
needed be set to:
LIBS=' -lsocket -lcrypt_i'
SunOS 4.x: When using the SunPro C compiler, you may want to use the
'-Xa' option instead of '-Xc', to enable some needed non-ANSI
Sunisms.
NeXT: To build fat binaries, use the --with-next-archs switch
described below.
QNX: Chris Herborth (chrish@qnx.com) writes:
configure works best if you use GNU bash; a port is available on
ftp.qnx.com in /usr/free. I used the following process to build,
test and install Python 1.5.x under QNX:
1) CONFIG_SHELL=/usr/local/bin/bash CC=cc RANLIB=: \
./configure --verbose --without-gcc --with-libm=""
2) edit Modules/Setup to activate everything that makes sense for
your system... tested here at QNX with the following modules:
array, audioop, binascii, cPickle, cStringIO, cmath,
crypt, curses, errno, fcntl, gdbm, grp, imageop,
_locale, math, md5, new, operator, parser, pcre,
posix, pwd, readline, regex, reop, rgbimg, rotor,
select, signal, socket, soundex, strop, struct,
syslog, termios, time, timing, zlib, audioop, imageop, rgbimg
3) make SHELL=/usr/local/bin/bash
or, if you feel the need for speed:
make SHELL=/usr/local/bin/bash OPT="-5 -Oil+nrt"
4) make SHELL=/usr/local/bin/bash test
Using GNU readline 2.2 seems to behave strangely, but I
think that's a problem with my readline 2.2 port. :-\
5) make SHELL=/usr/local/bin/bash install
If you get SIGSEGVs while running Python (I haven't yet, but
I've only run small programs and the test cases), you're
probably running out of stack; the default 32k could be a
little tight. To increase the stack size, edit the Makefile
to read: LDFLAGS = -N 48k
BeOS: Chris Herborth (chrish@qnx.com) writes:
See BeOS/README for notes about compiling/installing Python on
BeOS R3 or later. Note that only the PowerPC platform is
supported for R3; both PowerPC and x86 are supported for R4.
Cray T3E: Konrad Hinsen writes:
1) Don't use gcc. It compiles Python/graminit.c into something
that the Cray assembler doesn't like. Cray's cc seems to work
fine.
2) Comment out modules md5 (won't compile) and audioop (will
crash the interpreter during the test suite).
If you run the test suite, two tests will fail (rotate and
binascii), but these are not the modules you'd expect to need
on a Cray.
SGI: SGI's standard "make" utility (/bin/make or /usr/bin/make)
does not check whether a command actually changed the file it
is supposed to build. This means that whenever you say "make"
it will redo the link step. The remedy is to use SGI's much
smarter "smake" utility (/usr/sbin/smake), or GNU make. If
you set the first line of the Makefile to #!/usr/sbin/smake
smake will be invoked by make (likewise for GNU make).
WARNING: There are bugs in the optimizer of some versions of
SGI's compilers that can cause bus errors or other strange
behavior, especially on numerical operations. To avoid this,
try building with "make OPT=".
OS/2: If you are running Warp3 or Warp4 and have IBM's VisualAge C/C++
compiler installed, just change into the pc\os2vacpp directory
and type NMAKE. Threading and sockets are supported by default
in the resulting binaries of PYTHON15.DLL and PYTHON.EXE.
Monterey (64-bit AIX): The current Monterey C compiler (Visual Age)
uses the OBJECT_MODE={32|64} environment variable to set the
compilation mode to either 32-bit or 64-bit (32-bit mode is
the default). Presumably you want 64-bit compilation mode for
this 64-bit OS. As a result you must first set OBJECT_MODE=64
in your environment before configuring (./configure) or
building (make) Python on Monterey.
Reliant UNIX: The thread support does not compile on Reliant UNIX, and
there is a (minor) problem in the configure script for that
platform as well. This should be resolved in time for a
future release.
Mac OS X: You need to add the "-traditional-cpp" option to the
compiler command line for the Mac OS X Public Beta. This is
appearantly a bug in the default pre-processor, and is
expected not to be a problem with future versions. Run
configure with "OPT='-g -traditional-cpp' ./configure
--with-suffix=.exe --with-dyld" to add this
option. One of the regular expression tests fails due to the
small stack size used by default (how to change this?), and
the test_largefile test is only expected to work on a Unix UFS
filesystem (how to check for this on Mac OS X?).
Cygwin: Cygwin Python builds OOTB when configured as follows:
configure --with-threads=no
assuming Cygwin 1.1.8-2 and gcc 2.95.3-1 or later. At the time
of this writing, Cygwin pthread support is being significantly
enhanced. Hopefully, there will be a Cygwin Python with thread
support soon.
Cygwin Python supports the building of shared extensions via the
traditional Misc/Makefile.pre.in and the newer distutils methods.
On NT/2000, the following regression tests fail:
test_poll (hang)
test_strftime
Due to the test_poll hang on NT/2000, one should run the
regression test using the following:
PYTHONPATH= ./python.exe -tt ./Lib/test/regrtest.py -l -x test_poll
On 9X/Me, in addition the above NT/2000 failures, it has been
reported that the following regression tests also fail:
test_pwd
test_select (hang)
test_socket
Due to the test_poll and test_select hang on 9X/Me, one should
run the regression test using the following:
PYTHONPATH= ./python.exe -tt ./Lib/test/regrtest.py -l -x test_poll
-x test_select
Help trying to track down the root causes for these known problems
will be greatly appreciated.
Configuring threads
-------------------
As of Python 2.0, threads are enabled by default. If you wish to
compile without threads, or if your thread support is broken, pass the
--with-threads=no switch to configure. Unfortunately, on some
platforms, additional compiler and/or linker options are required for
threads to work properly. Below is a table of those options,
collected by Bill Janssen. We would love to automate this process
more, but the information below is not enough to write a patch for the
configure.in file, so manual intervention is required. If you patch
the configure.in file and are confident that the patch works, please
send in the patch. (Don't bother patching the configure script itself
-- it is regenerated each the configure.in file changes.)
Compiler switches for threads
.............................
The definition of _REENTRANT should be configured automatically, if
that does not work on your system, or if _REENTRANT is defined
incorrectly, please report that as a bug.
OS/Compiler/threads Switches for use with threads
(POSIX is draft 10, DCE is draft 4) compile & link
SunOS 5.{1-5}/{gcc,SunPro cc}/solaris -mt
SunOS 5.5/{gcc,SunPro cc}/POSIX (nothing)
DEC OSF/1 3.x/cc/DCE -threads
(butenhof@zko.dec.com)
Digital UNIX 4.x/cc/DCE -threads
(butenhof@zko.dec.com)
Digital UNIX 4.x/cc/POSIX -pthread
(butenhof@zko.dec.com)
AIX 4.1.4/cc_r/d7 (nothing)
(buhrt@iquest.net)
AIX 4.1.4/cc_r4/DCE (nothing)
(buhrt@iquest.net)
IRIX 6.2/cc/POSIX (nothing)
(robertl@cwi.nl)
Testing
-------
To test the interpreter, type "make test" in the top-level directory.
This runs the test set twice (once with no compiled files, once with
the compiled files left by the previous test run). The test set
produces some output. You can generally ignore the messages about
skipped tests due to optional features which can't be imported. (If
you want to test those modules, edit Modules/Setup to configure them.)
If a message is printed about a failed test or a traceback or core
dump is produced, something is wrong. On some Linux systems (those
that are not yet using glibc 6), test_strftime fails due to a
non-standard implementation of strftime() in the C library. Please
ignore this, or upgrade to glibc version 6.
IMPORTANT: If the tests fail and you decide to mail a bug report,
*don't* include the output of "make test". It is useless. Run the
failing test manually, as follows:
python ../Lib/test/test_whatever.py
(substituting the top of the source tree for .. if you built in a
different directory). This runs the test in verbose mode.
Installing
----------
To install the Python binary, library modules, shared library modules
(see below), include files, configuration files, and the manual page,
just type
make install
This will install all platform-independent files in subdirectories of
the directory given with the --prefix option to configure or to the
`prefix' Make variable (default /usr/local). All binary and other
platform-specific files will be installed in subdirectories if the
directory given by --exec-prefix or the `exec_prefix' Make variable
(defaults to the --prefix directory) is given.
All subdirectories created will have Python's version number in their
name, e.g. the library modules are installed in
"/usr/local/lib/python<version>/" by default, where <version> is the
<major>.<minor> release number (e.g. "2.1"). The Python binary is
installed as "python<version>" and a hard link named "python" is
created. The only file not installed with a version number in its
name is the manual page, installed as "/usr/local/man/man1/python.1"
by default.
If you have a previous installation of Python that you don't
want to replace yet, use
make altinstall
This installs the same set of files as "make install" except it
doesn't create the hard link to "python<version>" named "python" and
it doesn't install the manual page at all.
Alpha/beta revision levels are stripped from the executable and
library filenames during installation. For example, Python2.1a2 will
install as python2.1, overwriting the previous python2.1. To avoid
this, you could set the Makefile VERSION variable manually
(e.g. VERSION=2.1a2) before running "make install" or "make altinstall".
The only thing you may have to install manually is the Python mode for
Emacs found in Misc/python-mode.el. (But then again, more recent
versions of Emacs may already have it.) Follow the instructions that
came with Emacs for installation of site-specific files.
Miscellaneous issues
====================
Emacs mode
----------
There's an excellent Emacs editing mode for Python code; see the file
Misc/python-mode.el. Originally written by the famous Tim Peters, it
is now maintained by the equally famous Barry Warsaw (it's no
coincidence that they now both work on the same team). The latest
version, along with various other contributed Python-related Emacs
goodies, is online at http://www.python.org/emacs/python-mode. And
if you are planning to edit the Python C code, please pick up the
latest version of CC Mode http://www.python.org/emacs/cc-mode; it
contains a "python" style used throughout most of the Python C source
files. (Newer versions of Emacs or XEmacs may already come with the
latest version of python-mode.)
The Tk interface
----------------
Tk (the user interface component of John Ousterhout's Tcl language) is
also usable from Python. Since this requires that you first build and
install Tcl/Tk, the Tk interface is not enabled by default when
building Python from source. Python supports Tcl/Tk version 8.0 and
higher.
See http://dev.ajubasolutions.com/ for more info on Tcl/Tk, including
the on-line manual pages.
Distribution structure
----------------------
Most subdirectories have their own README files. Most files have
comments.
.cvsignore Additional filename matching patterns for CVS to ignore
BeOS/ Files specific to the BeOS port
Demo/ Demonstration scripts, modules and programs
Doc/ Documentation sources (LaTeX)
Grammar/ Input for the parser generator
Include/ Public header files
LICENSE Licensing information
Lib/ Python library modules
Makefile.pre.in Source from which config.status creates the Makefile.pre
Misc/ Miscellaneous useful files
Modules/ Implementation of most built-in modules
Objects/ Implementation of most built-in object types
PC/ Files specific to PC ports (DOS, Windows, OS/2)
PCbuild/ Build directory for Microsoft Visual C++
Parser/ The parser and tokenizer and their input handling
Python/ The byte-compiler and interpreter
README The file you're reading now
Tools/ Some useful programs written in Python
acconfig.h Additional input for the GNU autoheader program
config.h.in Source from which config.h is created (GNU autoheader output)
configure Configuration shell script (GNU autoconf output)
configure.in Configuration specification (input for GNU autoconf)
install-sh Shell script used to install files
The following files will (may) be created in the toplevel directory by
the configuration and build processes:
Makefile Build rules
Makefile.pre Build rules before running Modules/makesetup
buildno Keeps track of the build number
config.cache Cache of configuration variables
config.h Configuration header
config.log Log from last configure run
config.status Status from last run of the configure script
getbuildinfo.o Object file from Modules/getbuildinfo.c
libpython<version>.a The library archive
python The executable interpreter
tags, TAGS Tags files for vi and Emacs
That's all, folks!
------------------