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

  • Thread starter fog37
  • Start date
  • Tags
    module
In summary, The conversation discusses an issue with importing a custom module in Jupyter notebooks. The speaker encountered an error when trying to import the module and eventually solved it by converting the .ipynb file to a .py script and placing them in the same folder. They wonder if there are other ways to solve this issue without conversion. Suggestions include copying the code into a .py file or publishing it as a package on PyPl.
  • #1
fog37
1,569
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
  • #3
Perfect! Thank you pbuk
 
  • #4
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
 

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

Why is my "import" not working in Jupyter notebook with the notebook module?

The most common reason for this issue is a missing or incorrect package installation. Make sure that the package you are trying to import is installed correctly using the correct package manager for your environment.

How do I troubleshoot "import" errors in Jupyter notebook?

First, check if the package is correctly installed. If it is, then check if you are using the correct import statement for the package. If the error persists, try restarting the notebook kernel or the entire Jupyter notebook session.

Why am I getting a "module not found" error when trying to import a package in Jupyter notebook?

This error usually occurs when the package is not installed in the same environment as your Jupyter notebook. Make sure the package is installed in the same environment and try again.

Can I import custom modules in Jupyter notebook?

Yes, you can import custom modules in Jupyter notebook. Make sure the module is saved in the same directory as your notebook or in a directory added to the sys.path list.

How do I import a package in Jupyter notebook using a different name?

You can use the "as" keyword to import a package with a different name in Jupyter notebook. For example, "import numpy as np" will import the numpy package with the name "np" for ease of use in your code.

Similar threads

Replies
17
Views
2K
Replies
2
Views
1K
Replies
12
Views
9K
Replies
8
Views
2K
Replies
8
Views
1K
Replies
9
Views
1K
Replies
4
Views
6K
Replies
14
Views
5K
Back
Top