Packages‎ > ‎

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

  1. download module python-myModule-1.1.2.tar.gz
  2. unpack modul: gunzip -c python-myModule-1.1.2.tar.gz | tar xf -   
  3. go to directory: cd python-myModule-1.1.2
  4. 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

http://docs.python.org/3.3/install/index.html#install-index

Subpages (1): Check modul version
Comments