Import Modules
Modules (packages, libraries) are collections of functions that needs to be assinged (imported) with import before using it in Python.
1) function call requires module prefix
import math
x = math.log(5)
2) import all module functions to use without modul prefix
from math import *
x = log(5)
3) import only selected functions
from math import log, sqrt, sin
x = log(5)
4) change name of imported function
from math import log as ln
x = ln(5)
5) change name of imported module
import math as m
x = m.log(5)
Note, external modules needs to be locally installed on the computer before importing in Python.
Install Modules
download module python-myModule-1.1.2.tar.gz
unpack modul: gunzip -c python-myModule-1.1.2.tar.gz | tar xf -
go to directory: cd python-myModule-1.1.2
run: python setup.py install
or for local installation (no root access):
python setup.py install --user
needs to set the path in environment variable:
export PYTHONPATH=/path/to/my/library:$PYTHONPATH e.g.:
export PYTHONPATH=$HOME/.local/lib/python2.6/site-packages:$PYTHONPATH
http://docs.python.org/2/install/index.html#standard-build-and-install
http://docs.python.org/2/install/index.html#alternate-installation