| Version 44 (modified by , 16 years ago) ( diff ) |
|---|
Using virtualenv with Chimera
Adding python packages to Chimera is possible and a great way to do this, while preserving the state of the Chimera distribution, is to use virtualenv. First, add easy_install add then 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
![[Chimera Issue Tracking System]](/trac/chimera/chrome/site/chimera_logo.png)