import sys import os path = sys.executable print path folder = path[ 0 : path.rfind( os.sep ) ] print folder 效果: