Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'nbformat' #94

Open
sahinakkaya opened this issue Sep 14, 2023 · 4 comments
Open

KeyError: 'nbformat' #94

sahinakkaya opened this issue Sep 14, 2023 · 4 comments

Comments

@sahinakkaya
Copy link

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
Copy link
Owner

luk400 commented Sep 17, 2023

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
Copy link
Author

sahinakkaya commented Sep 19, 2023

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
Copy link
Author

Does this also happen with other ipynb files?

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

@sahinakkaya
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants