Home/Support/Support Forum/ImportError no module named ''
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

ImportError no module named ''

0 votes
Hello All,

I have created a small scheduler as a few objects to work with it. I am trying to organize my project by placing this code into a python package. I have created my package and copied it to the lib folder on the device. I import it into my code as follows:

from SchedulerPackage import Scheduler
from SchedulerPackage import PinControlledTask
from SchedulerPackage import TimedTask

Before my code even has a chance to run the program crashes on the imports giving the error:
Traceback (most recent call last):
File "main", line 5, in <module>
File "/flash/lib/SchedulerPackage/__init__.py", line 1, in <module>
File "/flash/lib/SchedulerPackage/PinControlledTask.py", line 4, in <module>
TypeError: cannot create 'module' instances

My package has an __init__.py and following the read me on the github page I could be able to use my created classes.

I am willing to share my code, I really just need to figure out why I can not access/create the included objects.
asked Jun 19, 2020 in Python by SinCitiesSin New to the Community (4 points)
edited Jun 19, 2020 by SinCitiesSin

Please log in or register to answer this question.

2 Answers

0 votes
I fixed the issue on my own. I was importing the classes incorrectly.

The correct import is

from SchedulerPackage.Scheduler import Scheduler
from SchedulerPackage.PinControlledTask import PinControlledTask
from SchedulerPackage.TimedTask import TimedTask
answered Jun 19, 2020 by SinCitiesSin New to the Community (4 points)
0 votes
You need a file named __init__.py (two underscores on each side) in every folder in the hierarchy. This is what python looks for to know that it should access a particular folder. The files are meant to contain initialization instructions but even if you create them empty this will solve it. To get rid of this error “ImportError: No module named”, you just need to create __init__.py in the appropriate directory and everything will work fine.

answered Aug 13, 2020 by creigelde New to the Community (1 point)