question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing Python Notebooks/Files Fails

See original GitHub issue

Bug report for Colab: http://colab.research.google.com/.

  • Describe the current behavior:

When importing another colab notebook file the following errors are returned (the bug is due to improper capitalization in module data for values such as true and null–the first letter of true should be capitalized, while null should be replaced by None or NotImplemented, maybe):

  • For notebooks with the private outputs setting disabled (issue at “execution_count”:null):

NameError Traceback (most recent call last) <ipython-input-2-e5202152c002> in <module>() 1 true = True 2 print(sys.path) ----> 3 from Hi import hi as hihi

/content/drive/My Drive/Colab Notebooks/Hi.py in <module>() ----> 1 {“nbformat”:4,“nbformat_minor”:0,“metadata”:{“colab”:{“name”:“Hi.py”,“provenance”:[],“collapsed_sections”:[],“authorship_tag”:“ABX9TyMP9MRH+DF9eO52boVUemSM”},“kernelspec”:{“name”:“python3”,“display_name”:“Python 3”}},“cells”:[{“cell_type”:“code”,“metadata”:{“id”:“tCywtH2Fa-1v”,“colab_type”:“code”,“colab”:{},“cellView”:“both”},“source”:[“def hi():\n”," print("Hi")"],“execution_count”:null,“outputs”:[]}]}…

NameError: name ‘null’ is not defined

  • For notebooks with the private outputs setting enabled (issue at “private_outputs”:true):

NameError Traceback (most recent call last) <ipython-input-4-e5202152c002> in <module>() 1 true = True 2 print(sys.path) ----> 3 from Hi import hi as hihi

/content/drive/My Drive/Colab Notebooks/Hi.py in <module>() ----> 1 {“nbformat”:4,“nbformat_minor”:0,“metadata”:{“colab”:{“name”:“Hi.py”,“provenance”:[],“private_outputs”:true,“collapsed_sections”:[],“authorship_tag”:“ABX9TyMP9MRH+DF9eO52boVUemSM”},“kernelspec”:{“name”:“python3”,“display_name”:“Python 3”}},“cells”:[{“cell_type”:“code”,“metadata”:{“id”:“tCywtH2Fa-1v”,“colab_type”:“code”,“colab”:{},“cellView”:“both”},“source”:[“def hi():\n”," print("Hi")"],“execution_count”:null,“outputs”:[0;34…

NameError: name ‘true’ is not defined

  • Describe the expected behavior:

The import should work without error. The module properties should be capitalized/named according to the appropriate corresponding Python constants during the import process to resolve the existing errors.

  • The web browser you are using (Chrome, Firefox, Safari, etc.):

Chrome

  • Link (not screenshot!) to a minimal, public, self-contained notebook that reproduces this issue (click the Share button, then Get Shareable Link):

Hi.py (tried both with private outputs enabled and with private outputs disabled):

def hi():
    print("Hi")

TestImporter.ipynb

import sys
if not 'drive/My Drive/Colab Notebooks/' in sys.path:
    sys.path.append('drive/My Drive/Colab Notebooks/')
from Hi import hi as hihi
hihi.hi()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chaoscommencercommented, Jun 25, 2020

Yup, I downloaded it, deleted the copy on G Drive, and re-uploaded, and it was recognized as a python file and worked correctly afterwards. Thanks!

0reactions
craigcitrocommented, Jun 25, 2020

No, changing the file name will have no effect on the contents.

You can use File -> Download .py to save a notebook file as a .py file from the colab UI.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import fails on jupyter-notebook - python - Stack Overflow
I found the issue to be a duplicate of import from local directory. Specifically, "Python 2.5 for Ubuntu 8.10 does not have the...
Read more >
What to do when things go wrong - The Jupyter Notebook
Jupyter fails to start​​ If Jupyter gives an error that it can't find notebook , check with pip or conda that the notebook...
Read more >
How to Import Python Module Files into Jupyter Notebooks
How to Import python files into jupyter notebooksGet FREE Tutorials, Free Books, plus other FREE Resources ...
Read more >
Calling Functions from Other Files - Problem Solving with Python
This file, myfunctions.py can be imported into another script (another .py file), or Jupyter Notebook. Remember the file that contains the function ...
Read more >
"import" in Jupyter notebook not working ... - Physics Forums
ipynb file. Upon importing the module into a different notebook using the instruction import module001, I received the error that the module was ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found