| Store | Cart

ActiveState Docs

ActivePython 2.7 Documentation

Loading...

You are here: ActivePython User Guide » Getting Started

Getting Started with ActivePython 2.7

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 the Install Notes to find out how.) So now what? This page will help you get started using ActivePython 2.7 quickly and effectively.

Getting Started on Windows

Install Location %SystemDrive%\Python27 (usually C:\Python27) by default, but can be specified at install time
Local Documentation The ActivePython Documentation link in the ActiveState ActivePython 2.7 program group of the Start menu.

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.7.5.6 (ActiveState Software Inc.) based on
Python 2.7.5 (#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 description 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.7 with links created in /usr/local/bin
Local Documentation Open the "Help Viewer" application (/System/Library/CoreServices/Help Viewer.app). Select "ActivePython 2.7 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 setup on Mac OS X 10.4 (Tiger) does not put /usr/local/bin on your PATH.

# Place the following in your ~/.bashrc file.
PATH=/usr/local/bin:$PATH; export 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.7.5.6 (ActiveState Software Inc.) based on
Python 2.7.5 (#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 ActiveTcl 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. You can either install the latest release version of PyObjC using PyPM or build it yourself 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.
  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 install
    
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.7 by default, but can be specified at install time
Local Documentation Open /opt/ActivePython-2.7/doc/python2.7/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.7 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.7/bin:$PATH; export PATH

# If you use the tcsh shell place the following in
# your ~/.cshrc file.
setenv PATH /opt/ActivePython-2.7/bin:$PATH

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

sudo ln -sf /opt/ActivePython-2.7/bin/python2.7 /usr/local/bin/python2.7
sudo ln -sf /usr/local/bin/python2.7 /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.7.5.6 (ActiveState Software Inc.) based on
Python 2.7.5 (#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/ASpy27 by default, but can be specified at install time
Local Documentation Open /opt/ASpy27/doc/python2.7/index.html in your browser.

Running Python and the Interactive Shell

The ActivePython installer on Solaris installs to /opt/ASpy27 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/ASpy27/bin:$PATH; export PATH

# If you use the tcsh shell place the following in
# your ~/.cshrc file.
setenv PATH /opt/ASpy27/bin:$PATH

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

sudo ln -sf /opt/ASpy27/bin/python2.7 /usr/local/bin/python2.7
sudo ln -sf /usr/local/bin/python2.7 /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.7.5.6 (ActiveState Software Inc.) based on
Python 2.7.5 (#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.