Chapter 1: Installing Leo

This chapter tells how to install and run Leo.

Important:

If you have any problems installing Leo, please ask for help on Leo’s help forum:

System requirements

Leo will work on any platform that supports Python 2.4 or later and Tk 8.4 or later. For Qt ui, Qt 4.4 or newer (and compatible PyQt) is required.

  • Download the latest version of Leo from Leo’s download page.

  • Download Python from: http://python.org/

  • Most installations of Python have Tk pre-installed. If your doesn’t, you may download it from: http://tcl.activestate.com/software/tcltk/

    Warning: When building Tcl on Linux, do not specify “–enable-threads”. Only use Tcl with the default “threads not enabled” case.

  • Leo uses Pmw (Python Mega Widgets). Leo’s extensions folder contains a copy of Pmw for use if needed. Leo first tries to import Pmw normally. If that fails, Leo will use the version of Pmw in the extensions folder.

Leo’s HOME directory

Python’s HOME environment variable specifies Leo’s HOME directory. See http://docs.python.org/lib/os-procinfo.html for details.

Leo uses os.expanduser(‘~’) to determine the HOME directory if no HOME environment variable exists.

Leo puts several files in your HOME/.leo directory: .leoID.txt, .leoRecentFiles.txt, and myLeoSettings.leo.

How to install Leo on Linux

Download the latest version of Leo (a .zip file) from Leo’s download page.

Unzip the downloaded .zip file into the unpacked folder in your home directory. The unpacked folder will be called something like leo-4-5.

You now have two choices:

  1. You can run Leo from your home directory. Just add ~/leo-4-5 to your path.

  2. You can install leo into /usr/local/lib and /usr/local/bin by running Leo’s install script as follows:

    cd ~/leo-4-4-3-final
    chmod u+x install
    sudo ./install

The install script will instruct you to add /usr/local/bin to your path. You can, instead, add the following link:

sudo ln -s /usr/local/lib/leo/ /usr/local/lib/python2.5/site-packages/

Now you are ready to run Leo.

Installing Leo on MacOS X

Installing Leo on MacOS 10.5 (Leopard) is straightforward.

  1. MacOS 10.5 comes with Python pre-installed. See http://www.python.org/download/mac/ and http://wiki.python.org/moin/MacPython/Leopard for information about using the latest version of Python.

  2. Download and install bzr:

  3. Get Leo’s sources from Leo’s trunk:

    cd ~
    mkdir leo.repo
    cd leo.repo
    bzr init
    bzr branch lp:leo-editor
    cd leo-editor
  4. You can run the tk version of Leo as follows:

    python launchLeo.py --gui=tk
  5. If you already have Qt and PyQt installed, you can run the qt version of Leo as follows:

    python launchLeo.py --gui=qt
  6. If you don’t have Qt or PyQt installed, you will have to install Qt and PyQt

    from sources. There does not seem to be any pre-built binaries.

    A: You may need to install XCode from http://developer.apple.com/mac/

    in order to get a development environment.

    B: Download and install the sip package, following the direction at

    http://www.riverbankcomputing.co.uk/software/sip/download

    C: Download the OpenSource Qt libraries for Mac from

    http://www.qtsoftware.com/downloads

    D: At various points along the way you will need to build the sources:

    python configure.py
    make
    sudo make install

Installing Leo on Windows

Leo is distributed at present only as a .zip file.

Another way is to append the path to the unpacked folder to the Windows PYTHONPATH environment variable.

Now that you have installed Leo and told Python where to find Leo, you are ready to run Leo.

Note: If you haven’t already created a HOME environment variable, it would be good to define home to be “%USERPROFILE%My Documents”. You can check whether HOME exists by typing ‘echo %HOME%’ (without the quotes) in a console window.

How to associate Leo with .leo files on Windows

Leo will open .leo files automatically provided that you associate leo.py with .leo files. Here is how to open Leo when double-clicking a .leo file on Windows 2K or XP:

  • In Windows 2K or XP, go to Start->Settings->Control panel, open the Folder Options tab.
  • Select the file types tab. Press the New button.
  • Enter Leo into the Create New File Extension field. Press OK.
  • With Leo still highlighted in the Registered File Types list box, press the Advanced button.
  • Change the default file type field to something like Leo Literate Outline.
  • Press the Icon button and browse to the LeoDoc icon in Leo’s Icons folder.
  • Click OK. This gets the icons right and registers the description of the .leo file.

You now have to tell windows what to do to open the file properly:

  • Press the new button to open the New Action window.

  • In the Action field type Open, then type one of the following lines:

    <python install dir>\pythonw.exe   <path-to-unpacked-folder>\launchLeo.py "%1"
    <python install dir>\python.exe -i <path-to-unpacked-folder>\launchLeo.py "%1"

Important: <path-to-unpacked-folder> refers to the full path to the directory with a name like Leo-x-y, where x and y are version numbers. This unpacked folder must contain a folder called ‘leo’.

Important: The -i option is not valid when using pythonw.exe. Any call to pythonw -i will cause pythonw.exe to exit immediately.

The first line opens Leo files with no console window. The second line opens Leo files with a console window and leaves the window open after Leo exits. You should now be able to double click on a leo file in explorer with Leo.

Tracking the development version

Many users will want to track the development version of Leo, in order to stay on top of the latest features and bugfixes. Running the development version is quite safe and easy, and it’s also a requirement if you want to contribute to Leo.

  1. First, you need to get Bazaar (bzr) from http://bazaar-vcs.org. For windows users we recommend the standalone installer - the python installer may have problems pushing to Launchpad. Plain bzr installer only contains the command line version, so you might want to augment that with a friendly GUI - qbzr is recommended as it’s the easiest one to install. It provides command like bzr qlog, bzr qannotate etc.

  2. Get Leo from launchpad by doing:

    bzr branch lp:leo-editor

And that’s it! You can run leo/core/leo.py directly. When you want to refresh the code with latest modifications from Launchpad, run bzr pull.

If you make modifications to Leo (with the interest in sharing them with the Leo community), you can check them in to your local branch by doing bzr checkin. Now, to actually request your changes to be merged to Leo trunk, you need a Launchpad account with RSA keys in place. There is showmedo video about how to accomplish this in Windows using puttygen and pageant at http://showmedo.com/videos/video?name=1510070&fromSeriesID=151.

After your Launchpad account is set up, go to https://launchpad.net/leo-editor, choose “Code” tab -> Register Branch, select Branch type “Hosted” and fill in descriptive details about the branch. After that, go to the branch home page from Code tab again, and copy-paste the push command line to terminal. For example, for branch:

https://code.launchpad.net/~leo-editor-team/leo-editor/mod_rclick

The push command is:

bzr push bzr+ssh://my_name@bazaar.launchpad.net/~leo-editor-team/leo-editor/mod_rclick

You may wish to add –remember command line option to bzr push, to direct all future pushes to that location. Then, you only need to execute bzr push.

After your branch is pushed, you can email the Leo mailing list and request it to be reviewed and merged to trunk.

Running Leo

You can run Leo from a Python interpreter as follows:

import leo
leo.run() # runs Leo, opening a new outline or,
leo.run(fileName=aFileName) # runs Leo, opening the given file name.

Another way to run Leo is as follows:

cd <path-to-launchLeo.py>
python launchLeo.py %1

Here are some tips that may make running Leo easier:

Linux

The following shell script will allow you to open foo.leo files by typing leo foo:

#!/bin/sh
python <leopath>launchLeo.py $1

where <leopath> is the path to the directory containing the leo directory.

Windows

If you have associated .leo files with Leo you may run Leo by double-clicking any .leo file. You can also use a batch file. Put the following .bat file in c:\Windows:

cd <path-to-leo>
c:\python25\python <path-to-leo>launchLeo.py %1

where <path-to-leo> is the path to the directory containing the leo directory.

This opens the file specified by the first argument (%1).

The first time you start Leo, a dialog will ask you for a unique identifier. If you are using cvs, use your cvs login name. Otherwise your initials will do. Leo stores this identifier in the file .leoID.txt. Leo attempts to create leoID.txt in the .leo sub-directory of your home directory, then in Leo’s config directory, and finally in Leo’s core directory. You can change this identifier at any time by editing .leoID.txt.

Running Leo in batch mode

On startup, Leo looks for two arguments of the form:

--script scriptFile

If found, Leo enters batch mode. In batch mode Leo does not show any windows. Leo assumes the scriptFile contains a Python script and executes the contents of that file using Leo’s Execute Script command. By default, Leo sends all output to the console window. Scripts in the scriptFile may disable or enable this output by calling app.log.disable or app.log.enable

Scripts in the scriptFile may execute any of Leo’s commands except the Edit Body and Edit Headline commands. Those commands require interaction with the user. For example, the following batch script reads a Leo file and prints all the headlines in that file:

path = r"<path-to-folder-containing-the-leo-folder>\leo\test\test.leo"

g.app.log.disable() # disable reading messages while opening the file
flag,newFrame = g.openWithFileName(path,None)
g.app.log.enable() # re-enable the log.

for p in newFrame.c.allNodes_iter():
    g.es(g.toEncodedString(p.h,"utf-8"))

How to install the Aspell spell checker

You must install the Aspell package if you want to use Leo’s Spell tab.

  1. Download and install the Aspell package from http://aspell.sourceforge.net/ Typically this will create a directory called Aspell/bin
  2. If you are using Python 2.3 or Python 2.4 you must copy a dll from Leo’s extensions folder to the Aspell/bin directory. This step is not needed if you are using Python 2.5 or later. Leo’s extensions folder comes with two dll’s: aspell23.pyd and aspell24.pyd, for Python 2.3 and 2.4 respectively. Make a copy of the appropriate dll, rename it to be aspell.pyd, and copy the renamed aspell.pyd file to Aspell/bin.
  3. Specify the location of the Aspell and Aspell/bin directories using the aspell_dir and aspell_bin_dir settings in LeoSettings.leo.