I have a local (not in Colab) Jupyter notebook that calls a function from another Jupyter notebook, it works fine. I've used David Rinck's answer from here: import a function from another .ipynb file and used this line to import the function:
from ipynb.fs.full.MyFunctions import MyFunction
I've imported these two notebooks into Colab and when I run the main notebook I get the following error:
No module named 'ipynb.fs.full.MyFunctions'
What have I missed in the process of importing to Colab?
(I've run !pip install ipynb
in Colab as well)
If you expand the files tab in Colab you can navigate to the files in Google Drive. Then you can right click on the file or folder you want and do Copy path . You can then paste this into the cell where path_to_module is defined.
py file), or Jupyter Notebook. Remember the file that contains the function definitions and the file calling the functions must be in the same directory. To use the functions written in one file inside another file include the import line, from filename import function_name .
To import from a Python file, see Reference source code files using git. Or, package the file into a Python library, create an Azure Databricks library from that Python library, and install the library into the cluster you use to run your notebook.
You can use the import-ipynb
package.
Starting by installing:
!pip install import_ipynb
import import_ipynb
Then,
import "your .ipynb file"
For Example, I have a sqroot.ipynb
file with a function
def sqroot(x):
return x**.5
We can run this function using the following:
import sqroot
sqroot.sqroot(2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With