Skip to content

Conversion of a simple .ipynb to py then back to ipynb gives "KeyError: 'env'" #792

Closed
@liar666

Description

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "a=5\n",
    "print('hello',a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "argv": [
    "python",
    "-m",
    "ipykernel_launcher",
    "-f",
    "{connection_file}"
   ],
   "display_name": "Python 3",
   "env": null,
   "interrupt_mode": "signal",
   "language": "python",
   "metadata": null,
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "name": "utils1.ipynb"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

First convertsion work:

$ jupytext --to py:percent --from ipynb utils1.ipynb
[jupytext] Reading utils1.ipynb in format ipynb
[jupytext] Updating the timestamp of utils1.py

Conversion back to original does not

$ jupytext --from py:percent --to ipynb utils1.py
[jupytext] Reading utils1.py in format py:percent
Traceback (most recent call last):
  File "/home/gmuller/Python/DataScience/bin/jupytext", line 8, in <module>
    sys.exit(jupytext())
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/cli.py", line 427, in jupytext
    exit_code += jupytext_single_file(nb_file, args, log)
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/cli.py", line 494, in jupytext_single_file
    notebook = read(nb_file, fmt=fmt, config=config)
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/jupytext.py", line 435, in read
    return read(stream, as_version=as_version, fmt=fmt, config=config, **kwargs)
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/jupytext.py", line 444, in read
    return reads(fp.read(), fmt, config=config, **kwargs)
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/jupytext.py", line 384, in reads
    format_name = read_format_from_metadata(text, ext) or fmt.get("format_name")
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/formats.py", line 280, in read_format_from_metadata
    metadata = read_metadata(text, ext)
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/formats.py", line 259, in read_metadata
    metadata, _, _, _ = header_to_metadata_and_cell(lines, comment, ext)
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/header.py", line 228, in header_to_metadata_and_cell
    recursive_update(metadata, yaml.safe_load("\n".join(jupyter))["jupyter"])
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/header.py", line 148, in recursive_update
    target[key] = recursive_update(target.get(key, {}), value)
  File "/home/gmuller/Python/DataScience/lib/python3.8/site-packages/jupytext/header.py", line 146, in recursive_update
    del target[key]
KeyError: 'env'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions