wiki:VirtualEnv

Version 41 (modified by Darren Weber, 16 years ago) ( diff )

--

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. Also, see additional tips on Chimera development with eclipse-PyDev and spyder.

Installing Chimera

Get a stable release or a 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-daily 
Extracting files.  This may take a few minutes.
Executing command: './chimera.exe -q -d /home/dweber/src/Chimera64-daily'
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-daily/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-daily. To install the desktop menu and icons:

$HOME/src/Chimera64-daily/bin/xdg-setup install

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. The CHIMERA path must point to a hard-link, not a sym-link, in the directory tree. Warning: do not set these environment variables for daily work with Chimera, they are to be set for a shell session that is only required during installation of additional python packages into the Chimera distribution of python.

# For a daily build, use:
export CHIMERA=$($HOME/src/Chimera64-daily/bin/chimera --root)
# For an svn-build, use: 
#export CHIMERA=$($HOME/src/Chimera64-svn/bin/chimera --root)
export PATH=${CHIMERA}/bin/${PATH} 
export LD_LIBRARY_PATH=${CHIMERA}/lib

Adding python distribution tools to the Chimera installation

Now get the distribute or the 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 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 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. For example,

export CHIMERA=$($HOME/src/Chimera64-daily/bin/chimera --root)
export PATH=${CHIMERA}/bin/:${PATH} 
export LD_LIBRARY_PATH=${CHIMERA}/lib
${CHIMERA}/bin/easy_install pylint
${CHIMERA}/bin/easy_install pyflakes

A bash script to install setup tools and virtualenv

#!/bin/bash
# Default Chimera install path
CHIMERA="${HOME}/src/Chimera64-daily"
# Optional input parameter for Chimera install path
if [ $1 ]; then
	CHIMERA=$1
fi
# Test the existence of the $CHIMERA install path
if [ -d $CHIMERA ]; then
	echo "Chimera install path: ${CHIMERA}"
else
	echo "Invalid Chimera install path: ${CHIMERA}"
	exit 1
fi
export LD_LIBRARY_PATH=${CHIMERA}/lib
export PATH=${CHIMERA}/bin:${PATH}
mkdir -p ~/Downloads/
cd ~/Downloads/
rm -rf distribute*
curl -O http://python-distribute.org/distribute_setup.py
${CHIMERA}/bin/python2.7 distribute_setup.py 
${CHIMERA}/bin/easy_install virtualenv

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 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 $HOME/src/chimera-virtualenv/bin/activate
cd $HOME/src/chimera-virtualenv
export CHIMERA=$(cd $HOME/src/Chimera64-daily && pwd -P)
#export CHIMERA=$(cd $HOME/src/Chimera64-build && pwd -P)
export LD_LIBRARY_PATH=$CHIMERA/lib
cat > chimeraImportStartup.py <<END
import sys
import os
print os.getenv('CHIMERA')
sys.path.append(os.path.join(os.getenv('CHIMERA'), 'share'))
sys.path.append(os.path.join(os.getenv('CHIMERA'), 'lib'))
import chimera
print chimera.version.version
for s in sys.path:
    print s
END
export PYTHONSTARTUP=./chimeraImportStartup.py
python

An interactive terminal session might look 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
Note: See TracWiki for help on using the wiki.