Install python module without admin rights

Most remote servers are governed by system admin rights. Python modules are abundantly available but cannot be installed in the default location without admin rights.

An alternative approach is to install the modules in the local home directory and point the python interpreter to access the modules placed in the local home directory.

Installation

Change directory into the source directory of the python module. Make sure the setup.py exists in the directory and execute the following command.

$ python setup.py install –home=/home/user/package_dir

At the shell command prompt, execute the following command

$ export PYTHONPATH=”${PYTHONPATH}:/home/user/package_dir/lib/python”

At the python Command Line Interpreter (CLI), test the following to confirm that the module has installed.

$ python

>>> import module_name

 

 

Python Dictionary

Creating a dictionary

>>> my_dict[‘key1′]=’value1’
>>> my_dict[‘key2′]=’value2’
>>> my_dict[‘key3′]=’value3’
>>> my_dict
{‘key3’: ‘value3’, ‘key2’: ‘value2’, ‘key1’: ‘value1’}

or

>>> my_dict = {‘A’:0, ‘B’:1, ‘C’:2, ‘D’:3, ‘E’:4}

Iterating through python dictionary

>>> my_dict = {‘A’:0, ‘B’:1, ‘C’:2, ‘D’:3, ‘E’:4}
>>> for key, value in my_dict.iteritems():
>>>  print key, value
A 0
C 2
B 1
E 4
D 3

We can also use my_dict.iterkeys() or my_dict.itervalues() to itearte of keys or values in the dictionary