incorrect version or language
JoyeBright opened this issue ยท 8 comments
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
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?
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.
Btw, my workaround was to use import-ipynb instead.
Ah, thank you - I ended up finding importnb and working with that, but I appreciate you sharing! :)
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"
}
It looks like pull request #51 will fix this issue
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
(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.