Not Importing modules on autostart of python program

Here is the dummy code if want to try it out yourself:

import cv2
import numpy as np
try:
    from firebase import firebase
    from firebase.firebase import FirebaseApplication
except Exception as error:
    f=open("error.txt","a")
    f.write(str(error))
    f.close()



cap=cv2.VideoCapture(0)


#establishing connnection with the database for the first time

while True:
    try:
        #firebase_message = firebase.FirebaseApplication("<link to the database>", None)    
        break
    except:
        continue
print("Connectionion Established")

while(cap.isOpened()):
    _,frame=cap.read()

   
   # cv2.imshow('frame',result)
    k = cv2.waitKey(1) & 0xff
    if k == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

Use this to run your python program on boot

please test this dummy code and share if you have a solution to this issue