Edited
You are opening the file in the wrong directory, importing a module does not change your working directory. Do this instead
import yaml
import os
def Keypairs():
print os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(os.path.dirpath(__file__),'keypairs.yaml')) as f:
return yaml.load(f)