1

I am working on a project on a Raspberry Pi where I need to create a security camera system. I have 3 python files for this project one for live streaming, another one for motion detection and finally the last for activating the motion detection file from an android application. I am trying to make the live stream and motion detection file use the same camera. In the live stream file(live.py) I have imported a socketserver module to make the live stream, which works well when run. However, when I am trying to import the live.py file into the motion detection file(motion.py), I am getting an Import Error. The error is shown below:

Traceback (most recent call last):
 File "motion.py", line 10, in <module>
      import live.py
 File "/home/pi/codes/live.py", line 7, in <module>
      import socketserver
 ImportError:No module named socketserver

I am very confused, I don't know what this error is. Any help would be very appreciated. Thank you.

1 Answers1

0

it looks like live.py is in a subdirectory. Python cannot access python files that are NOT in python packages. So, you need to ensure that all the folders that live.py is in are PYTHON PACKAGES.

To make a folder into a python package simply add a init.py file to each folder (you do not need to write any code in this file)

Then when you import live.py the import will look like this

from root.folder_name import live
Wizard
  • 462
  • 1
  • 6
  • 14