ActivePython User Guide

You are here: ActivePython User Guide » Getting Started

Getting Started with ActivePython 2.4

Welcome to ActivePython! Python is an interpreted dynamic programming language . ActivePython is a binary distribution of that language: a no-hassle, ready to install package to lets you get to the business of writing Python software.

Presumably you have now installed ActivePython. (If not, head over to Install Notes to find out how.) So now what? This page will help you get started using ActivePython 2.4 quickly and effectively.

Getting Started on Windows

Install Location %SystemDrive%\Python24 (usually C:\Python24) by default, but can be specified at install time
Local Documentation

Running Python and the Interactive Shell

The ActivePython installer on Windows will automatically add python to your PATH environment variable (Win98/WinME users may have to reboot for this change to take effect) so you should be able to run python at the DOS shell to start the Python interactive shell. You can also start the Python interactive shell from the ActivePython program group under the Windows Start menu. You should see something like the following:

ActivePython 2.4.3.12 (ActiveState Software Inc.) based on
Python 2.4.3 (#65, Mar 30 2005, 09:33:37 [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

You can use the Python shell to interactively run Python code. This can be very useful development and debugging tool. Learn how to use Python's built-in dir() and help() introspection functions to dive into Python objects. For example, try running the following:

>>> import os.path
>>> dir(os.path)
list of members of os.path module...
>>> help(os.path)
MAN page-like desciption of the os.path module...
>>> help(os.path.join)
help on the join function...

Read the Python Tutorial for more information.

GUI Programming

Tkinter is Python's binding to the cross-platform Tk GUI toolkit and is a default part of any ActivePython installation.

wxPython is another popular cross-platform GUI programming toolkit. It is available separately from http://www.wxpython.org/.

Python includes a large number of GUI programming toolkits and while Tkinter and wxPython are the primary two contenders on Windows, there are some other options. The included PyWin32 extensions provide some bindings to Windows UI routines (win32ui, win32uiole). As well there are the PyQT and PyGTK bindings to the QT and GTK GUI toolkits, respectively. They are both available separately. Both QT's and GTK's main roots are in the Linux/Unix platform, but they are available for Windows as well.

Windows-specific Libraries and Tools

ActivePython on Windows includes the PyWin32 extensions. These extensions provide bindings to much of the Windows API, full Windows COM integration, and the Pythonwin IDE (a basic Python editing environment). Read more about the Windows API and COM integration in the PyWin32 documentation (only include in the ActivePython documentation on Windows).

Getting Started on Mac OS X

Install Location /Library/Frameworks/Python.framework/Versions/2.4 with links created in /usr/local/bin
Local Documentation Open the "Help Viewer" application (/System/Library/CoreServices/Help Viewer.app). Select "ActivePython 2.4 Help" from Help Viewer's "Library" menu. More info...

Running Python and the Interactive Shell

The ActivePython installer on Mac OS X installs symlinks for running python, pythonw, and pydoc to /usr/local/bin. If this directory is not already on your PATH you can add it manually as follows. Note that the default setups on Mac OS X 10.3 (Panther) and 10.4 (Tiger) do not put /usr/local/bin on your PATH.

# If you use the Bash shell (the default on Mac OS 10.3 and up) place
# the following in your ~/.bashrc file.
PATH=/usr/local/bin:$PATH; export PATH
# If you use the tcsh shell place the following in
# your ~/.cshrc file.
setenv PATH /usr/local/bin:$PATH

Open the Terminal application (/Applications/Utilities/Terminal.app) and type python. (If you already had a terminal open you may need to start a new one to see the PATH changes.) You should see something like the following:

ActivePython 2.4.3.12 (ActiveState Software Inc.) based on
Python 2.4.3 (#1, Mar 30 2005, 09:33:37)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

You can use the Python shell to interactively run Python code. This can be very useful development and debugging tool. Learn how to use Python's built-in dir() and help() introspection functions to dive into Python objects. For example, try running the following:

>>> import os.path
>>> dir(os.path)
list of members of os.path module...
>>> help(os.path)
MAN page-like desciption of the os.path module...
>>> help(os.path.join)
help on the join function...

Read the Python Tutorial for more information.

pythonw
On Mac OS X, any process that provides a GUI (i.e. talks to the Aqua window manager) needs to be launched in a certain way. The pythonw command (just a stub that calls the actual Python executable as required) is provided for this purpose. If your Python code provides a GUI, launch it with pythonw instead of python. (There is a hack, but it is not recommended.)

GUI Programming

Tkinter is Python's binding to the cross-platform Tk GUI toolkit. ActivePython includes Tkinter by default, but on Mac OS X you must also install either ActiveTcl or TclTkAqua to use Tkinter.

wxPython is another popular cross-platform GUI programming toolkit. It is available separately from http://www.wxpython.org/.

The PyObjC project provides a bridge between Python and Apple's Objective-C system. Part of this system is the Cocao toolkit for Mac OS X GUI programming. See below for more information.

Mac OS X-specific Libraries and Tools

Documentation

In addition to the Python Library Reference that most Python developers will want to be familiar with, Python developers on Mac OS X may also want to take a look at the Macintosh Module Reference. Please be aware, however, that some of this documentation is out-of-date (some of referring to Mac OS 9, a.k.a. Mac Classic). The most useful sections will be MacOS Toolbox Modules and possibly MacPython OSA Modules, which discusses current bindings to Apple's OSA (Open Scripting Architecture, of which AppleScript is an implementation) system.

PyObjC

The PyObjC project, as mentioned above, provides a bridge between Python and Apple's Objective-C system. In particular it provides the ability to write complete Mac OS X GUI applications in Python. PyObjC is, at the time of this writing, being very actively developed. There is currently no binary distribution of PyObjC for Python 2.4, however you can build and install the latest PyObjC into your ActivePython installation as follows:

  1. If you do not have a /Developer directory, you will first need to install the Apple Developer Tools. These are often available on a separate CD that shipped with your Mac hardware. Alternatively you can download them from Apple's developer site after registering for a (free) ADC membership.
  2. You will need a Subversion client, svn, with which to checkout the latest PyObjC sources. You can find a Subversion installer here or here.
  3. Run the following to download, build, and install PyObjC:
    svn co http://svn.red-bean.com/pyobjc/trunk/pyobjc/
        cd pyobjc
        /usr/local/bin/python setup.py bdist_mpkg --open
        
py2app

py2app (available separately from here) is an extension to Python's standard distutils system for building and distributing Python software. If would like to distribute your Python software as full-fledged Mac OS X applications and/or with Mac OS X Installer packages you should take a look at py2app.

Getting Started on Linux, AIX, HP-UX

Install Location /opt/ActivePython-2.4 by default, but can be specified at install time
Local Documentation Open /opt/ActivePython-2.4/doc/python2.4/index.html in your browser.

Running Python and the Interactive Shell

The ActivePython installer on Linux, AIX and HP-UX installs to /opt/ActivePython-2.4 by default, but an alternate install directory (for example, somewhere in your home directory) can be specified at install time. To be able to simply run python from the shell you either need to add this install directory's bin dir to your PATH:

# If you use the Bash shell place the following in
# your ~/.bashrc file.
PATH=/opt/ActivePython-2.4/bin:$PATH; export PATH
# If you use the tcsh shell place the following in
# your ~/.cshrc file.
setenv PATH /opt/ActivePython-2.4/bin:$PATH

or create symlinks from some directory alread on your PATH (commonly /usr/local/bin) to python:

sudo ln -sf /opt/ActivePython-2.4/bin/python2.4 /usr/local/bin/python2.4
sudo ln -sf /usr/local/bin/python2.4 /usr/local/bin/python

Type python in the shell. (If you modified your shell startup script, you may need to start a new shell to see the PATH changes.) You should see something like the following:

ActivePython 2.4.3.12 (ActiveState Software Inc.) based on
Python 2.4.3 (#1, Mar 30 2005, 09:33:37)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

You can use the Python shell to interactively run Python code. This can be very useful development and debugging tool. Learn how to use Python's built-in dir() and help() introspection functions to dive into Python objects. For example, try running the following:

>>> import os.path
>>> dir(os.path)
list of members of os.path module...
>>> help(os.path)
MAN page-like desciption of the os.path module...
>>> help(os.path.join)
help on the join function...

Read the Python Tutorial for more information.

GUI Programming

Tkinter is Python's binding to the cross-platform Tk GUI toolkit and is a default part of any ActivePython installation on Linux, AIX and HP-UX.

wxPython is another popular cross-platform GUI programming toolkit. It is available separately from http://www.wxpython.org/.

As well there are the PyQT and PyGTK bindings to the QT and GTK GUI toolkits, respectively. They are both available separately.

Getting Started on Solaris

Install Location /opt/ASpy24 by default, but can be specified at install time
Local Documentation Open /opt/ASpy24/doc/python2.4/index.html in your browser.

Running Python and the Interactive Shell

The ActivePython installer on Solaris installs to /opt/ASpy24 by default, but an alternate install directory (for example, somewhere in your home directory) can be specified at install time. To be able to simply run python from the shell you either need to add this install directory's bin dir to your PATH:

# If you use the Bash shell place the following in
# your ~/.bashrc file.
PATH=/opt/ASpy24/bin:$PATH; export PATH
# If you use the tcsh shell place the following in
# your ~/.cshrc file.
setenv PATH /opt/ASpy24/bin:$PATH

or create symlinks from some directory alread on your PATH (commonly /usr/local/bin) to python:

sudo ln -sf /opt/ASpy24/bin/python2.4 /usr/local/bin/python2.4
sudo ln -sf /usr/local/bin/python2.4 /usr/local/bin/python

Type python in the shell. (If you modified your shell startup script, you may need to start a new shell to see the PATH changes.) You should see something like the following:

ActivePython 2.4.3.12 (ActiveState Software Inc.) based on
Python 2.4.3 (#2, Mar 30 2005, 09:33:37) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>>

You can use the Python shell to interactively run Python code. This can be very useful development and debugging tool. Learn how to use Python's built-in dir() and help() introspection functions to dive into Python objects. For example, try running the following:

>>> import os.path
>>> dir(os.path)
list of members of os.path module...
>>> help(os.path)
MAN page-like desciption of the os.path module...
>>> help(os.path.join)
help on the join function...

Read the Python Tutorial for more information.