Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named "file1.py"; test1 is not a package

I'm trying to modularize my code and I'm having issues with it.

My folder is constructed like this:

code
   |_main.py
   |_test1
           |_calcA.py (which contains a method)
   |_test2
           |_calcB.py (which contains another method)
   |_test3
           |_calcC.py (which contains another method)

Now my main.py contains these lines:

import sys; import pprint
pprint.pprint(sys.path)
from test1.calccircle.py import calcA
from test2.calctriangle.py import calcB
from test3.calccarre.py import calcB

The following error comes:

ImportError: No module named 'test1.calcA.py'; 'test1.calcA' is not a package

like image 391
LiquidSnake Avatar asked Dec 06 '22 11:12

LiquidSnake


1 Answers

You don't need to specify .py while importing modules. Python knows your modules are Python code only. So remove .py while importing modules in Python.

like image 172
Mufeed Avatar answered Dec 29 '22 12:12

Mufeed