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

  • Thread starter Thread starter fog37
  • Start date Start date
  • Tags Tags
    module
AI Thread Summary
When working with Jupyter notebooks, importing a custom module saved as a .ipynb file can lead to a "module not found" error. This issue arises because Jupyter notebooks do not support direct imports like traditional Python scripts. A solution is to convert the .ipynb file into a .py script and ensure both files are in the same directory, which resolves the import issue. Alternative methods include copying the code from the notebook into a .py file or publishing the module on PyPI for easier access. The discussion emphasizes the need for efficient ways to manage module imports in Jupyter environments.
fog37
Messages
1,566
Reaction score
108
TL;DR Summary
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
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top