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

incorrect version or language #49

Open
JoyeBright opened this issue May 21, 2020 · 8 comments
Open

incorrect version or language #49

JoyeBright opened this issue May 21, 2020 · 8 comments

Comments

@JoyeBright
Copy link

I have strived to import an external ipynb, but I got the following error:

ImportError: Could not import /content/.ipynb for ipynb.fs.full.: incorrect version or language

I was wondering if I could know that you have ever experienced the same issue, please!

NB: I am running the codes on the Google Colab.

Thanks in advance

@AnupamSaraph
Copy link

Unable to import ipynb as it gives the error: "ipynb\fs\full_init_.py", line 39, in get_code raise ImportError('Could not import {path} for {fn}: incorrect version or language"

Is this ipynb import supported only for some python versions?

@rajkundu
Copy link

Same issue here using Python 3.8.5 on macOS 10.15.7. Perhaps it has to do with me using "/usr/local/bin/python3"? I'm working in VS Code.

@olaviinha
Copy link

Btw, my workaround was to use import-ipynb instead.

@rajkundu
Copy link

Ah, thank you - I ended up finding importnb and working with that, but I appreciate you sharing! :)

@abergerSRS
Copy link

I too experienced this error. I found that the validate_nb() method in "utils.py" is searching the within notebook's kernelspec dictionary for the dictionary key language. My particular notebook did not have this key. It only has name and display_name, which would need to be further parsed to determine that language_name == 'python'

"metadata": {
  "kernelspec": {
   "name": "python394jvsc74a57bd0be098d32f57b1a2b9aacbade952c5e427778cda6d97bd24f3e84e87f053b8dae",
   "display_name": "Python 3.9.4 64-bit"
  }

@abergerSRS
Copy link

It looks like pull request #51 will fix this issue

@davidleejy
Copy link

davidleejy commented Sep 15, 2021

It would seem that this issue is still present on Google Colab. PR #51 doesn't seem to have been merged. The latest commit on main branch in this repo was on Oct 2017. To anyone reading this, I think this repo may not be active at the moment.

Versions:

Python 3.7.11

ipynb 0.5.1

Example:

# asdf.ipynb
def foo(a,b):
    print(a,b)
# abc.ipynb
!pip install ipynb
from google.colab import drive
drive.mount('/content/drive/')
import sys
sys.path.append('/content/drive/MyDrive/Colab Notebooks/')
import ipynb.fs.defs.asdf

gives:

ImportError                               Traceback (most recent call last)

<ipython-input-6-1be176fa1f93> in <module>()
----> 1 import ipynb.fs.full.asdf

/usr/local/lib/python3.7/dist-packages/ipynb/fs/full/__init__.py in get_code(self, fullname)
     39                     raise ImportError('Could not import {path} for {fn}: incorrect version or language'.format(
     40                         path=self.path,
---> 41                         fn=fullname
     42                     ))
     43                 return self.source_to_code(code_from_ipynb(nb), self.path)

ImportError: Could not import /content/drive/MyDrive/Colab Notebooks/asdf.ipynb for ipynb.fs.full.asdf: incorrect version or language

@felipewhitaker
Copy link

(probably not recommended)

Following on @abergerSRS answer, I looked at what the utils/validate_nb(nb) function was doing and a quick (and certainly dirty) fix is open the ipynb metadata (open it using notes, for example) adding language to a dict like below.

{
  ...
   "metadata": {
     ...
    "kernelspec": {
      ...
     "language": "python" # <--- added line
    }
  ...
}

I do not know why this check is being made, and I am unaware of possible side effects. Therefore, I do not responsibilize myself if something goes wrong.

madziejm added a commit to madziejm/1e100-ibu that referenced this issue Feb 4, 2022
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

7 participants