pakage sys and os
import os
os.chdir(caffe_root)
# f 是文件的绝对路径或相对路径
os.remove(f)
sys.path
['../python',
'',
'/home/amax/caffe/python',
'/opt/caffe-master/python',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/local/lib/python2.7/dist-packages/pip-1.5.6-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/xgboost-0.6-py2.7.egg',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode',
'/usr/local/lib/python2.7/dist-packages/IPython/extensions',
'/home/amax/.ipython']
So,
sys.path.insert(0, caffe_root + 'python')
0 means insert in the front.
caffe_root = '../' # this file should be run from {caffe_root}/examples (otherwise change this line)
import sys
sys.path.insert(0, caffe_root + 'python')