Multiple Python installation

# Commands are tested on Ubuntu 14.04
# Install the python3 as Ubuntu 14.04 comes with Python2
sudo apt-get update -y && \
sudo apt-get install python-pip python3 python3-pip
# Let's manage two versions
# Ubuntu is already having pip2 as /usr/bin/pip. We need to remove it otherwise update-alternatives can't create symlinks
sudo rm /usr/bin/pip
sudo update-alternatives –install /usr/bin/python python /usr/bin/python2.7 10 –slave /usr/bin/pip pip /usr/bin/pip2
sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.5 20 –slave /usr/bin/pip pip /usr/bin/pip3.5
# Machine is configured for python3 at this point, let's see
python –version
— OR —
pip –version
# To switch b/w different versions
sudo update-alternatives –config python
# To see available versions
sudo update-alternatives –list python
# To remove link
sudo update-alternatives –remove gcc /usr/bin/python3.5

Control Caffe console output in python

If you are using Caffe framework in Python, you will find that its prints a lot of information on console. You can control this output by setting up an environment variable in python application:

os.environ['GLOG_minloglevel'] = '2'
import caffe

Following levels are available:

- Debug => 0
- Info => 1
- Warnings => 2
- Errors => 3

NOTE: ‘GLOG_minloglevel‘ must be set before `import caffe` statement otherwise it will not work.

FYI: Caffe uses Google logging module ( for logging output.

python debug

To print line number in python script for debugging purposes, use following line of codes to print file name, and line number to see what is going on inside the python script:

from inspect import currentframe, getframeinfo
frameinfo = getframeinfo(currentframe())
print "[Debug]", frameinfo.filename, frameinfo.lineno