Isiklikud vahendid
Oled siin: Algus Local HOWTOs Advanced Python setup
Tegevused dokumentidega

Advanced Python setup

by Pearu Peterson viimati muudetud 2012-06-19 13:51

Howto setup environment for advance Python usage

NEW VIRTUALENV BASED SETUP (RECOMMENDED)

As a prerequisite, install and run the following software:

# Ubuntu users
sudo apt-get install python-dev virtualenv liblapack-dev libatlas-base-dev g++
virtualenv sysbio
source sysbio/bin/activate

# Arch users
yaourt virtualenv2 atlas
virtualenv2 sysbio
source sysbio/bin/activate

Setup virtual environment

Run the following commands:

pip install numpy
pip install scipy
pip install ipython
# wx support: manually create links from wx python packages (wx, wxversion, gtk*.pth, cairo, glib, gobject) to sysbio/lib/pythonX.X/site-packages
# make sure that import gtk succeeds before installing matplotlib
pip install matplotlib
pip install -e svn+http://pylibtiff.googlecode.com/svn/trunk/
pip install -e svn+http://iocbio.googlecode.com/svn/trunk/

FINALIZE SETUP

Append the following lines to .bashrc

export PYTHONSTARTUP=~/.pythonrc.py
source ~/sysbio/bin/activate

Copy the following text to .pythonrc.py file

import os

try:
if os.environ.has_key('NOIPYTHON'):
raise ImportError
import sys
if sys.stdout is not sys.__stdout__:
raise ImportError,'ipython not usable in non-standard Python shell.'
import IPython
if IPython.__version__[:4]>='0.11':
try:
# pre 0.11 release:
from IPython.core.ipapp import launch_new_instance
launch_new_instance()
except ImportError:
# official 0.11 release:
from IPython import embed
embed()
sys.exit ()
shell = IPython.Shell.IPShell()
shell.IP.BANNER=''
shell.mainloop()
sys.exit()
except ImportError, msg:
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter,os
readline.parse_and_bind("tab: complete")
histfile = os.path.join(os.environ["HOME"], ".python_history")
try:
try: readline.read_history_file(histfile)
except IOError: pass
import atexit
atexit.register(readline.write_history_file, histfile)
del atexit
except AttributeError: pass
del os, histfile
del rlcompleter,readline

Re-login to make .bashrc changes effective. Run python that should open an IPython session. Configure IPython to your needs.

 

OLD SETUP (NOT RECOMMENDED)

 

Note for system administrator

Insert the following codelet to addsitepackages() function just after prefixes = [..] statement in /etc/python2.X/site.py file:

    opt_prefix = os.environ.get('PYTHONPREFIX', None)
if opt_prefix and opt_prefix not in prefixes:
prefixes.insert(0, opt_prefix)

Note for users

Add the following line to your .bashrc file (make sure that is is also loaded to .bash_profile):

export PYTHONPREFIX=/opt/python
export PATH=/opt/python/bin:$PATH
export LD_LIBRARY_PATH=/opt/matlab/bin/glnxa64:$LD_LIBRARY_PATH

Setting PYTHONPREFIX to /opt/python in this way will expose the following packages to Python users:

  • Numpy, Scipy from SVN - the latest and greatest versions
  • matplotlib from SVN
  • mlabraw 1b
  • traits from SVN

Using IPython as default python

For interactive work the usage of IPython is highly recommended. To use ipython by default, create file .pythonrc.py containing:

import os

try:
if os.environ.has_key('NOIPYTHON'):
raise ImportError
import sys
if sys.stdout is not sys.__stdout__:
raise ImportError,'ipython not usable in non-standard Python shell.'
import IPython
shell = IPython.Shell.IPShell()
shell.IP.BANNER=''
shell.mainloop()
sys.exit()
except ImportError:
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter,os
readline.parse_and_bind("tab: complete")
histfile = os.path.join(os.environ["HOME"], ".python_history")
try:
try: readline.read_history_file(histfile)
except IOError: pass
import atexit
atexit.register(readline.write_history_file, histfile)
del atexit
except AttributeError: pass
del os, histfile
del rlcompleter,readline

and add the following line to .bashrc file:

export PYTHONSTARTUP=~/.pythonrc.py

Loodud Plone, Avatud Lähtekoodiga Sisuhaldussüsteemi, abil