luk400 / vim-jukit

Jupyter-Notebook inspired Neovim/Vim Plugin
MIT License
587 stars 23 forks source link

KeyError: 'nbformat' #94

Open sahinakkaya opened 1 year ago

sahinakkaya commented 1 year ago

I am getting key error while trying to convert ipynb file to py file. The notebook file can be found here. When I examine the file, I already see a line which looks like "nbformat": 4, so I have no idea why it can't find the key 'nbformat'. I also tried converting it with jupyter nbconvert --to notebook --nbformat 4 <FILENAME> but nothing has changed.

Error invoking 'python_execute' on channel 7 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "/Users/***/.local/share/nvim/site/pack/packer/start/vim-jukit/helpers/ipynb_convert
/convert.py", line 123, in convert
    language, nb = get_nb_and_language(nb, lang)
  File "/Users/***/.local/share/nvim/site/pack/packer/start/vim-jukit/helpers/ipynb_convert
/util.py", line 11, in get_nb_and_language
    assert nb["nbformat"] > 3, (
KeyError: 'nbformat'
luk400 commented 1 year ago

I can't reproduce your problem, for me the notebook is correctly converted. What operating system are you using and whats your neovim and python version? Does this also happen with other ipynb files?

If you want to debug this yourself, you can also go into the vim-jukit/helpers/ipynb_convert directory and then execute the convert.py script manually, like so: python3 convert.py /full/path/to/Exercises.ipynb Set breakpoints and attach a debugger in the convert.py script as needed to see where it goes wrong and why nb doesn't contain the "nbformat" key.

sahinakkaya commented 1 year ago

I will try to debug it as you say. Thanks. Here are the output you asked for in case it helps:

❯ sw_vers
ProductName:            macOS
ProductVersion:         13.2.1
BuildVersion:           22D68

❯ nvim --version
NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.1/share/nvim"

Run :checkhealth for more info

❯ python --version
Python 3.10.6

I am running python in a virtual env using pyenv.

sahinakkaya commented 1 year ago

Does this also happen with other ipynb files?

No, the other files are correctly converted. For example, it can convert this just fine.

sahinakkaya commented 1 year ago

Ok, I found the problem. There is a bug which only occurs if the full path to the file contains whitespace. The directory name of the notebook I shared is this:

/Users/***/GitRepos/pandas_exercises/05_Merge/Fictitous Names

When I change "Fictitous Names" to "Fictitous_Names" everything works just fine.