| Installing Opus & UrbanSim > Installing on Mac | |
The following instructions are for installing Opus and UrbanSim on Mac OS X. The directions have been tested with Mac OS X Leopard (10.5) with an Intel processor. In the past we have also run UrbanSim on a Mac with a PPC processor, but haven't tested the instructions recently for that processor.
Opus and UrbanSim are implemented in Python, making heavy use of external numerical Python packages and other software. The version used in this guide is 2.5.1. If you use OS X Leopard (10.5), this version is already installed and you can skip to the next section. If you are using an earlier version of OS X however, you'll need to update Python.
The official Python website includes documentation, downloads, and much more. Go to the download section and get the latest version of Python 2.5 (at the time of writing 2.5.2) for Mac OS X. This is an installer that works on both PPC and Intel Macs. Double-click on the image to mount it, then double-click on the MacPython.mpkg package icon to install. When you're done you can unmount the image by clicking on the triangle symbol next to it in the Finder.
When you install a newer version of Python, the installer will put it earlier on the search path so that it will be found instead of the preinstalled one. You can still get to the old version via /usr/bin/python. We recommend that you keep the old version, since other applications may rely on it.
MySQL is an efficient, open-source SQL database. You don't need it to run the basic Eugene tutorial, although for serious use with your own dataset you will want a database of some sort. We are steadily reducing the dependencies on the particular database used with the goal of allowing Opus and UrbanSim to be used with any SQL database, but for now MySQL is probably your best option.
If you use MySQL you can either have a local copy or run on a shared server. You can also return and install MySQL later if you discover that you need it.
Opus works with MySQL 4.1 and 5.0.
In addition to MySQL itself, you might get the MySQL Query Browser for prowling around in UrbanSim databases using a graphical interface, and the MySQL Administrator. These are both available as binaries.
See the Opus/UrbanSim MySQL Installation and Configuration Page for additional specific configuration steps. This page is written for Windows, but is straightforward to use for the Mac as well.
Opus and Urbansim require a number of python packages, and make optional use of several others. Download and install them from the list of required, recommended and optional Python packages. Many packages have multiple versions, and are sometimes available in both dmg form and source. If you get a dmg (disk image) file, be sure to pick the one for Python 2.5. In addition to the general instructions at the above link, here are some additional Mac-specific suggestions for installing the libraries.
In order to install some of the packages, you'll need to compile the library from source. If you haven't already done so, you can install the optional Xcode package on one of the Install Disks that came with your Mac (for Mac OS X Leopard (10.5) it's Install Disk 2). You'll find the installation file named XcodeTools-version.mpkg inside the Xcode Tools folder on the installation disc.
If you have an older Mac, you may need to get a more up-to-date version of Xcode Tools than the one that came on your Install Disk. In particular if you get C compiler errors (such as not being able to find 'include' files), this may be the problem. To fix it, get the latest version of Xcode Tools from the Apple Tools Download page. You'll need to register (it's free) and login. A warning about the file size; it's over 900 MB.
Unfortunately Xcode doesn't come with a Fortran compiler, which is needed to build the SciPy package. You can download the GNU Fortran compiler from http://r.research.att.com/gfortran-4.2.3.dmg. The installation should be straightforward.
You can make a quick check that the compilers are installed by typing the commands
$ gcc --version
$ gfortran --version
and make sure that you get version information and not command not found errors.
Generally we recommend that you use Easy Install. EasyInstall is a Python module that can download, build (if necessary) and install Python packages with minimal user interaction. For more on Easy Install, visit the PEAK webpage. However, if EasyInstall doesn't work, or is over-eager to build some packages from source that are also available as dmg files, get these packages from the download site for that package (linked below for each package) or from pythonmac.org.
To install it; download ez_setup.py to your computer. Open a Terminal and locate the directory the file is in. Then type
$ sudo python ez_setup.py
If you are running a version of OS X earlier than 10.5, such as 10.4.9, download and install the following
If you are running Mac OS X Leopard (10.5), the two packages above are not necessary.
Install NumPy, SciPy, MatPlotLib, SQLAlchemy and Elixir by typing the following commands in a Terminal window:
$ sudo easy_install numpy
$ sudo easy_install scipy
$ sudo easy_install matplotlib
$ sudo easy_install SQLAlchemy
$ sudo easy_install Elixir
If for some reason easy_install fails to install any of the above packages, or if you do not want to use easy_install; you can click the package names to go to their homepage and follow the instructions on how to install them manually.
If you are using R, install RPy (http://rpy.sourceforge.net/). This is a Python interface for the statistical programming language R (tested with version 0.4.6).
If you need to use .dbf files (for example, those produced by ArcGIS), install dbfpy (you can get it from here).
If you are using a MySQL as a database, go ahead and install MySQL-python. Unfortunately the current version (1.2.2) has some issues with building on Mac OS X Leopard (10.5), so you can't install it using easy_install, since some source files need to be modified in order for it to build on Mac OS X.
To install it, go to the sourceforge page for MySQL-python and download the tarball. Then follow the steps provided here in order to be able to build and install the package. Note that MySQL should be installed before you install the MySQL-python package. You may need to put /usr/local/mysql/bin into your path before installing mysql-python to avoid getting an error.
You may get the following error after building and installing MySQL-python 1.2.2 on 10.3.9:
ImportError: dlcompat: dyld: /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python can't open library: /usr/local/mysql/lib/mysql/libmysqlclient_r.15.dylib (No such file or directory, errno = 2)
This may happen because the library it is looking for is in /usr/local/mysql/lib/, and not in a subfolder called mysql. Moving the files or creating aliases should fix the problem.
Finally install the QT framework from Trolltech, and PyQt which is the Python bindings for it. PyQt also requires SIP to be installed before you can build it. Instructions on how to do this follows.
Note: The installation process for Mac OS X Tiger (10.4) is similar as to the one described here, but seems to vary from user to user for reasons we haven't been able to pin down. This page has been useful to some users.
The "Qt for Open Source C++ development on Mac OS" page has both source and binary distributions available.
The binary distribution is under "Additional downloads", and contains a standard Mac OS X installation package.
Alternatively, you can install from source. There are instructions on the Qt site for doing this. The simple version is to unpack the source, and do:
$ cd path/to/qt-mac-opensource-src-version
$ sudo make install
This build will take a while.
First, get the SIP source from its download page. Unpack it somewhere, and then build it using the following, optionally replacing /Library/Python/2.5/site-packages with the path to your Python site-packages directory:
$ cd path/to/sip-version
$ python configure.py -d /Library/Python/2.5/site-packages
$ make
$ sudo make install
First, get PyQt from its download page. Be sure to get the Mac version. Unpack it somewhere, and then build it using the following, optionally replacing /Library/Python/2.5/site-packages with the path to your Python site-packages directory:
$ cd path/to/PyQt-mac-gpl-4.4.3
$ python configure.py -d /Library/Python/2.5/site-packages
$ make
$ sudo make install
Note that this build will also take a while.
Follow the directions on the Downloading the Opus/UrbanSim sample data and source code page.
UrbanSim requires the following environment variables. The first tells the Python interpreter where to find the Opus/UrbanSim code. The second tells the system where to find your cached data and configurations.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<key>PYTHONPATH</key>
<string>/Users/yourname/opus/src</string>
<key>OPUS_HOME</key>
<string>/Users/yourname/opus</string>
</dict>
</plist>
You need to reboot your machine after editing the environment.plist file for the new definitions to be seen. Unfortunately, the environment.plist technique for setting environment variables on the Mac doesn't seem to work on all machines. If you have trouble, try putting the definition in a .bashrc file as well.
If you mainly will access Opus and UrbanSim from a command shell, you can place the following lines in your .profile (again note the dot). If there is no such file, you can go ahead and create it.
export PYTHONPATH=/path/to/opus/src:$PYTHONPATH
export OPUSPATH=/path/to/opus
Of course, replace /path/to/opus with the actual path to your opus directory. Also note that the settings made in .profile won't be effective until the next Terminal session.
Finally, if you are going to be developing Opus and UrbanSim using an IDE, there is probably some way that you can set the PYTHONPATH to include opus on a per project basis if you don't want session-wide settings. You should note that you'll only be able to start Opus and UrbanSim from the IDE if you decide to do it this way.
Follow these instructions to test your installation.