"import" in Jupyter notebook not working with notebook module....

  • Thread starter Thread starter fog37
  • Start date Start date
  • Tags Tags
    module
Click For Summary
SUMMARY

The discussion centers on the challenges of importing Jupyter notebook modules, specifically when using the import statement with a custom module saved as a .ipynb file. The user encountered a "module not found" error, which was resolved by converting the .ipynb file to a .py script and ensuring both files were in the same directory. The conclusion drawn is that Jupyter notebooks cannot be directly imported as modules using the standard import syntax, necessitating conversion to Python scripts for successful imports.

PREREQUISITES
  • Understanding of Jupyter Notebook file structure and formats
  • Familiarity with Python scripting and module creation
  • Knowledge of file management in Python environments
  • Basic troubleshooting skills in Python import errors
NEXT STEPS
  • Explore methods for converting Jupyter notebooks to Python scripts using nbconvert
  • Learn about using Jupyter's import functionality with the nbimporter package
  • Research best practices for organizing Python modules within Jupyter environments
  • Investigate the use of PyPI for distributing Jupyter notebook modules
USEFUL FOR

Data scientists, Python developers, and educators who utilize Jupyter notebooks for coding and want to streamline their module imports and improve workflow efficiency.

fog37
Messages
1,566
Reaction score
108
TL;DR
import instruction in Jupyter notebook not working with module with .ipynb extension
Hello everyone,

I am writing Jupyter notebooks which are essentially JSON files. I wrote a custom module called module001 containing some functions and saved it as a .ipynb file. Upon importing the module into a different notebook using the instruction import module001, I received the error that the module was not found. I eventually solved the problem by converting the .ipynb module into a .py script and then placing the module and the script in the same folder. The import worked just fine. The lesson learned was that the module, as .ipynb, does not work with the import instruction.

Are there other more elegant or efficient ways to solve this issue instead of having to convert the notebook module to .py?

Thank you!
 
Technology news on Phys.org
Perfect! Thank you pbuk
 
fog37 said:
Perfect! Thank you pbuk
You can also copy/paste the python code into a regular .py file and use import from there, or even put it up on PyPl
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
6
Views
3K
  • · Replies 12 ·
Replies
12
Views
10K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 9 ·
Replies
9
Views
1K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 14 ·
Replies
14
Views
8K
  • · Replies 22 ·
Replies
22
Views
2K