Python Forum

Full Version: ModuleNotFoundError: No module named 'xxxx'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to Python and programming itself. I have got my working directory in ""'C:\\Users\\dell\\Desktop\\Python Practice'"". I have got a file "Python Basics.ipynb" in which I am working and it is saved in working directory. Now I have created a module with name Calc.ipynb in same working directory and this Calc has few functions which I want to call from "Python Basics.ipynb". But I am getting an error. Coding details below:

*******Calc.ipynb********************
def sum(a,b):
    return a+b
def sub (a,b):
    return a-b
def mul (a,b):
    return a*b
def div (a,b):
    return a/b
****************************
******"Python Basics.ipynb"**********************
###first I tried below code
import Calc
a = 9
b = 7
c = Calc.sum(a,b)
print (c)
Error/Response from system on execution:
ModuleNotFoundError
Error:
Traceback (most recent call last) <ipython-input-91-7f3fd0194649> in <module> 1 ## Modules - very importnat -- can create another file for my functions-- and then these funcitons can be called in my program 2 ## here - I have created a separate module as the new file in same folder directory- it will have few of the required funcitons ----> 3 import Calc 4 a = 9 5 b = 7 ModuleNotFoundError: No module named 'Calc'
---------------------------
Then I tried following code :
from Calc import *
a = 9
b = 7
c = sum(a,b)
print (c)
error is:
---------------------------------------------------------------------------
ModuleNotFoundError
Error:
Traceback (most recent call last) <ipython-input-87-bf78db7caed4> in <module> ----> 1 from Calc import * 2 a = 9 3 b = 7 4 c = sum(a,b) 5 print (c) ModuleNotFoundError: No module named 'Calc'
**************************************
Please guide where I am going wrong..
I don't normally use Jupyter notebooks, but the problem is that .ipynb files are not regular python files (.py files), so that they cannot be imported out of the box. I've found a blog post of a guy who explored 8 different ways to import a notebook into another notebook. I'm sure one of these ways will work for you.
(Feb-06-2020, 11:31 AM)Gribouillis Wrote: [ -> ]I don't normally use Jupyter notebooks, but the problem is that .ipynb files are not regular python files (.py files), so that they cannot be imported out of the box. I've found a blog post of a guy who explored 8 different ways to import a notebook into another notebook. I'm sure one of these ways will work for you.

Thanks!.. Actually I just converted the extension to .py and all is well. Thank You!!