== Installing Chimera and a Python Virtual Environment for Chimera Development == This page contains an example of a user installation of Chimera and additional configuration options to create a virtual python environment for development with Chimera. The Chimera distribution currently ships with a custom build of python2.7 (as of Aug, 2010). This custom python installation may not be compatible with any other installations of python on the system (including any site-packages in other python installations). The following examples provide a tidy way to access and add new packages in a virtual environment derived from the Chimera python installation. === Installing Chimera === Get a stable release or a [http://www.cgl.ucsf.edu/chimera/download.html#daily daily build of Chimera]. In the examples below, it was a daily build for a linux 64-bit system (dated 2010-08-24). To run the installation, without superuser privileges: {{{ cd ~/Downloads/ chmod +x chimera-alpha-linux_x86_64.exe mkdir -p $HOME/src ./chimera-alpha-linux_x86_64.exe }}} Here's an example of the interactive prompts and replies: {{{ UnZipSFX 5.41 of 16 April 2000, by Info-ZIP (Zip-Bugs@lists.wku.edu). Original path: '/home/dweber/Downloads' inflating: chimera_install_35bPbx/installer inflating: chimera_install_35bPbx/chimera.exe Enter install location: $HOME/src/Chimera64-2010-08-24 Extracting files. This may take a few minutes. Executing command: './chimera.exe -q -d /home/dweber/src/Chimera64-2010-08-24' UnZipSFX 5.52 of 28 February 2005, by Info-ZIP (http://www.info-zip.org). Install desktop menu and icon? yes To install desktop menu and icon, run: $HOME/src/Chimera64-2010-08-24/bin/xdg-setup install If run as root, then it installs for all users, otherwise it installs just for the current user. Install symbolic link to chimera for command line use in which directory? 0 -- no link 1 -- /usr/local/sbin 2 -- /usr/local/bin 3 -- /usr/sbin 4 -- /usr/bin 5 -- /sbin 6 -- /bin 7 -- /usr/games [hit Enter for default (0)]: }}} This installation did not use sudo privileges, so the install path was changed from {{{/opt/UCSF/Chimera64-2010-08-05}}} to {{{$HOME/src/Chimera64-2010-08-24}}}. To install the desktop menu and icons: {{{ $HOME/src/Chimera64-2010-08-24/bin/xdg-setup install }}} In addition, I like to setup a few symlinks, like so: {{{ cd ~/src ln -s Chimera64-2010-08-24 Chimera64-daily sudo ln -s $HOME/src/Chimera64-daily/bin/chimera /usr/local/bin/chimera }}} Lastly, a few environment variables are set to simplify executing the new installation programs. If your installation path is different, you will need to set the CHIMERA environment variable to your path. {{{ export CHIMERA=$HOME/src/Chimera64-daily export PATH=$PATH:$CHIMERA/bin/ export LD_LIBRARY_PATH=$CHIMERA/lib }}} === Adding python distribution tools to the Chimera installation === Now get the [http://pypi.python.org/pypi/distribute distribute] or the [http://pypi.python.org/pypi/setuptools setuptools] package installed into the Chimera python installation. Note the following has some version specific details that need attention for any current installation. At the time of writing (Aug, 2010), this installation used a specific daily-build of Chimera (2010-08-24) and a specific version of setuptools for the version of python that was built for Chimera (python2.7). Option A: to use [http://pypi.python.org/pypi/distribute distribute], try the following: {{{ cd ~/Downloads curl -O http://python-distribute.org/distribute_setup.py $CHIMERA/bin/python2.7 distribute_setup.py }}} Option B: to use [http://pypi.python.org/pypi/setuptools setuptools], try the following: {{{ cd ~/Downloads curl -O http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg sh setuptools-0.6c11-py2.7.egg --prefix=$CHIMERA }}} Now it's easy to use these tools for installation of any additional python packages into the Chimera python distribution. === Using virtualenv === Adding additional packages to the Chimera python distribution is now possible and a great way to do this, while preserving the state of the Chimera distribution, is to use [http://pypi.python.org/pypi/virtualenv virtualenv]. First, add the {{{virtualenv}}} package into the Chimera python installation, like so: {{{ $CHIMERA/bin/easy_install virtualenv $CHIMERA/bin/virtualenv --help }}} Now that {{{virtualenv}}} is installed in the Chimera python distribution, we can setup any additional custom virtual environments to add python packages into our custom development environment. As a regular user, the following will create a Chimera-specific development environment in ~/src/chimera-virtualenv: {{{ mkdir -p ~/src cd ~/src $CHIMERA/bin/virtualenv --distribute $HOME/src/chimera-virtualenv ls -al $HOME/src/chimera-virtualenv/ }}} Once this virtual environment is created, it can be activated and deactivated with the following commands (note how the system prompt changes to indicate that we have entered and left the virtual environment). {{{ source ~/src/chimera-virtualenv/bin/activate deactivate }}} === !VirtualEnv Python Development for Chimera === Now you can start the Chimera build of python and import the chimera module. First activate the {{{virtualenv}}} and confirm that it's using the right python. {{{ source ~/src/chimera-virtualenv/bin/activate python }}} In my case, the terminal session looked like this: {{{ $ source ~/src/chimera-virtualenv/bin/activate (chimera-virtualenv)$ which python /home/dweber/src/chimera-virtualenv/bin/python (chimera-virtualenv)$ python Python 2.7 (r27:82500, Aug 23 2010, 21:16:26) [GCC 4.2.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> import os >>> os.getenv('CHIMERA') '/home/dweber/src/Chimera64-daily' >>> sys.path.append(os.path.join(os.getenv('CHIMERA'), 'share')) >>> sys.path.append(os.path.join(os.getenv('CHIMERA'), 'lib')) >>> import chimera >>> chimera.version.version 'alpha version 1.5 (build 31253) 2010-08-24 01:28:28 GMT' >>> for s in sys.path: print s ... /home/dweber/src/chimera-virtualenv/lib/python2.7/site-packages/distribute-0.6.10-py2.7.egg /home/dweber/src/chimera-virtualenv/lib/python2.7/site-packages/pip-0.7.2-py2.7.egg /home/dweber/src/chimera-virtualenv/lib/python27.zip /home/dweber/src/chimera-virtualenv/lib/python2.7 /home/dweber/src/chimera-virtualenv/lib/python2.7/plat-linux2 /home/dweber/src/chimera-virtualenv/lib/python2.7/lib-tk /home/dweber/src/chimera-virtualenv/lib/python2.7/lib-old /home/dweber/src/chimera-virtualenv/lib/python2.7/lib-dynload /home/dweber/src/Chimera64-daily/lib/python2.7 /home/dweber/src/Chimera64-daily/lib/python2.7/plat-linux2 /home/dweber/src/Chimera64-daily/lib/python2.7/lib-tk /home/dweber/src/chimera-virtualenv/lib/python2.7/site-packages /home/dweber/src/Chimera64-daily/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg /home/dweber/src/Chimera64-daily/lib/python2.7/site-packages/virtualenv-1.4.9-py2.7.egg /home/dweber/src/Chimera64-daily/lib/python2.7/site-packages /home/dweber/src/Chimera64-daily/lib/python2.7/site-packages/PIL /home/dweber/src/Chimera64-daily/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info /home/dweber/src/Chimera64-daily/share /home/dweber/src/Chimera64-daily/lib >>> (chimera-virtualenv)$ deactivate $ }}} To add additional packages into the virtual environment, try using pip. {{{ $ source ~/src/chimera-virtualenv/bin/activate (chimera-virtualenv)$ pip --help Usage: pip COMMAND [OPTIONS] Options: --version show program's version number and exit -h, --help Show help -E DIR, --environment=DIR virtualenv environment to run pip in (either give the interpreter or the environment base directory) -s, --enable-site-packages Include site-packages in virtualenv if one is to be created. Ignored if --environment is not used or the virtualenv already exists. -v, --verbose Give more output -q, --quiet Give less output --log=FILENAME Log file where a complete (maximum verbosity) record will be kept --proxy=PROXY Specify a proxy in the form user:passwd@proxy.server:port. Note that the user:password@ is optional and required only if you are behind an authenticated proxy. If you provide user@proxy.server:port then you will be prompted for a password. --timeout=SECONDS, --default-timeout=SECONDS Set the socket timeout (default 15 seconds) Commands available: bundle: Create pybundles (archives containing multiple packages) freeze: Output all currently installed packages (exact versions) to stdout help: Show available commands install: Install packages search: Search PyPI uninstall: Uninstall packages unzip: Unzip individual packages zip: Zip individual packages }}} === Developing Chimera with spyder (a python IDE) === [http://www.youtube.com/watch?v=TRU6tQdyYqQ And now for something completely different]! How about installing the [http://packages.python.org/spyder/ spyder]. First, we need to install some [http://packages.python.org/spyder/installation.html#dependencies spyder dependencies], [http://www.riverbankcomputing.com/software/sip/intro sip] and [http://www.riverbankcomputing.co.uk/software/pyqt/intro PyQt]. (In the example below, sip and !PyQt are installed with sudo privileges only because Chimera was installed with those privileges. If you install Chimera without sudo privileges, try to run {{{make install}}} commands instead of {{{sudo make install}}}.) This example is based on an Ubuntu linux system that had packages installed for Qt4, PyQt4, and QScintilla2, which are [http://packages.python.org/spyder/installation.html#dependencies spyder dependencies]. Your system may need these installed, along with their development libraries and headers. Although those packages were installed on the system, they were not directly accessible to the Chimera python build. In my case, a solution was to download and build !PyQt4 within the Chimera virtual environment. {{{ source ~/src/chimera-virtualenv/bin/activate cd ~/Downloads curl -O http://www.riverbankcomputing.co.uk/static/Downloads/sip4/sip-4.10.5.tar.gz tar zxvf sip-4.10.5.tar.gz cd sip-4.10.5 python configure.py make make install deactivate }}} {{{ source ~/src/chimera-virtualenv/bin/activate cd ~/Downloads curl -O http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-x11-gpl-4.7.4.tar.gz tar zxvf PyQt-x11-gpl-4.7.4.tar.gz cd PyQt-x11-gpl-4.7.4 # configure without installing designer plugin or QScintilla API, as these # should be installed already by a prior installation of Qt4 or PyQt into the # system paths python configure.py --qmake=/usr/bin/qmake-qt4 --no-qsci-api --no-designer-plugin make make install deactivate }}} {{{ source ~/src/chimera-virtualenv/bin/activate cd ~/Downloads curl -O http://212.219.56.133/sites/www.ibiblio.org/gentoo/distfiles/QScintilla-gpl-2.4.3.tar.gz tar zxvf QScintilla-gpl-2.4.3.tar.gz cd QScintilla-gpl-2.4.3/Python python configure.py make make install # Ignore the failure for: cp -f QScintilla2.api /usr/share/qt4/qsci/api/python/QScintilla2.api # The QScintilla2.api file was installed by an Ubuntu package (don't overwrite it). # This was the last step in the install, everything else installed OK. deactivate }}} Let's check the additional module [http://packages.python.org/spyder/installation.html#dependencies dependencies for spyder]. The Chimera python installation includes modules for {{{numpy}}} and {{{matplotlib}}}. The install for {{{pylint}}} is easy, but {{{scipy}}} installation is not. {{{ source ~/src/chimera-virtualenv/bin/activate pip install pylint deactivate }}} That should satisfy most of the [http://packages.python.org/spyder/installation.html#dependencies spyder dependencies]. Now try to install spyder using pip. {{{ source ~/src/chimera-virtualenv/bin/activate pip install spyder deactivate }}} OK, if that works, then try to setup the environment and run spyder. {{{ source ~/src/chimera-virtualenv/bin/activate export CHIMERA=$HOME/src/Chimera64-daily export TCL_LIBRARY="$CHIMERA/lib/tcl8.6" export TCLLIBPATH="{$CHIMERA/lib}" unset TK_LIBRARY unset TIX_LIBRARY #export LD_PRELOAD=libotf.so export PATH=$PATH:$CHIMERA/bin unset PYTHONHOME unset PYTHONPATH spyder }}} If that fails (as it did for me), try using sudo privileges (this worked for me): {{{ sudo -i source /home/dweber/src/chimera-virtualenv/bin/activate export CHIMERA=/opt/UCSF/Chimera64-2010-08-24 export PATH=$PATH:$CHIMERA/bin/ export LD_LIBRARY_PATH=$CHIMERA/lib export LD_PRELOAD=libotf.so export TCL_LIBRARY="$CHIMERA/lib/tcl8.6" export TCLLIBPATH="{$CHIMERA/lib}" unset TK_LIBRARY unset TIX_LIBRARY unset PYTHONHOME unset PYTHONPATH spyder }}}