def set_jupyter_kernel_to_python_version(path, python_version=2):
    'Set notebook kernelspec to desired python version.\n\n    This also drops all other meta data from the notebook.\n    '
    for file_name in glob(os.path.join(path, '*.ipynb')):
        with open(file_name, 'r') as f:
            notebook_data = json.load(f)
        notebook_data['metadata'] = {'kernelspec': {'display_name': 'Python {}'.format(python_version), 'language': 'python', 'name': 'python{}'.format(python_version)}}
        with open(file_name, 'w') as f:
            json.dump(notebook_data, f, indent=2)
Set notebook kernelspec to desired python version.

This also drops all other meta data from the notebook.
def set_jupyter_kernel_to_python_version(path, python_version=2):
    'Set notebook kernelspec to desired python version.\n\n    This also drops all other meta data from the notebook.\n    '
    for file_name in glob(os.path.join(path, '*.ipynb')):
        with open(file_name, 'r') as f:
            notebook_data = json.load(f)
        notebook_data['metadata'] = {'kernelspec': {'display_name': 'Python {}'.format(python_version), 'language': 'python', 'name': 'python{}'.format(python_version)}}
        with open(file_name, 'w') as f:
            json.dump(notebook_data, f, indent=2)