Jul-01-2019, 10:29 PM
I'm trying to run a python script that previously worked on a new raspberry pi.
I'm new to python so any insight is appreciated!
## added scheduled on the minute instead of sleep time ## added upload to Google Drive from time import sleep from datetime import datetime from sh import gphoto2 as gp import signal, os, subprocess import schedule from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive ##SET UP GOOGLE DRIVE UPLOAD gauth = GoogleAuth() drive = GoogleDrive(gauth) gauth.LocalWebserverAuth() picID = "_earth_test_9" clearCommand = ["--folder", "/store_00020001/DCIM/100CANON","-R", "--delete-all-files"] triggerCommand = ["--trigger-capture"] downloadCommand = ["--get-all-files"] shot_date = datetime.now().strftime("%Y-%m-%d") folder_name = shot_date + picID save_location = "/home/pi/Documents/Earth_Test/" + folder_name def createSaveFolder(): try: os.makedirs(save_location) print("New save directory created for today!") except: print("Already created this save directory for today") os.chdir(save_location) def captureImages(): gp(triggerCommand) sleep(3) gp(downloadCommand) gp(clearCommand) def renameFiles (picID): for filename in os.listdir("."): if len(filename) < 13: if filename.endswith(".JPG"): os.rename(filename, photo_name) print("Success! JPG renamed") ## elif filename.endwith (".CR2"): ## os.rename(filename, (shot_time + picID + ".CR2")) ## print ("Hurray! Raw file renamed") def uploadImage(): file1 = drive.CreateFile() file1.SetContentFile('/home/pi/Documents/Earth_Test/' + folder_name + photo_name_slash) file1.Upload() print("Photo uploaded!") def timelapse (): print ("--------------") print ("START", datetime.now()) createSaveFolder() captureImages() renameFiles(picID) uploadImage() print ("END", datetime.now()) gp(clearCommand) schedule.every().minute.at(":00").do(timelapse) while True: shot_time = datetime.now().strftime("%Y-%m-%d" "%H:%M:%S") photo_name = shot_time + picID + ".JPG" photo_name_slash = "/" + shot_time + picID + ".JPG" schedule.run_pending() sleep (1)I've downloaded all the needed packages, including sh and gphoto2, but am getting this error message when I try to run the script.
Error:Traceback (most recent call last):
File "earth_test_9.py", line 7, in <module>
from sh import gphoto2 as gp
ImportError: cannot import name 'gphoto2' from 'sh' (/usr/local/lib/python3.7/dist-packages/sh.py)
I've tried to upgrade gphoto2 and sh, but no change.I'm new to python so any insight is appreciated!