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 install
    or for local installation (no root access):
    python 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

Subpages (1): Check modul version