Python Forum
TimeLapse Help - ImportError: No module named 'sh'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TimeLapse Help - ImportError: No module named 'sh'
#1
I'm new to python and am trying to write a code that will allow me to take time lapse photographs with my DSLR.

from time import sleep
from datetime import datetime
from sh import gphoto2 as gp
import signal, os, subprocess

shot_date = datetime.now().strftime("%Y-%m-%d")
shot_time = datetime.now().strftime("%Y-%m-%d" "%H:%M:%S")
pidID = "earth_test_3"

clearCommand = ["--folder", "/store_00020001/DCIM/100CANON","-R",
"--delete-all-files"]
triggerCommand = ["--trigger-capture"]
downloadCommand = ["--get-all-files"]

folder_name = shot_date + picID
save_location = "/home/pi/Desktop/earth_test_3/" + 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 (ID):
    for filename in os.listdir("."):
        if len(filename) < 13:
            if filename.endswith(".JPG"):
                os.rename(filename, (shot_time + ID + ".JPG"))
                print("Sucess! JPG renamed")
            elif filename.endwith (".CR2"):
                os.rename(filename, (shot_time + ID + ".CR2"))
                print ("Hurray! Raw file renamed")

gp(clearCommand)

while True:
    createSaveFolder()
    captureImages()
    renameFiles(picID)
    sleep (60)
I followed the code from a tutorial, but am receiving this error when I run it through the terminal.

Error:
Traceback (most recent call last); File "earth_test_4.py", line 3, in <module> from sh import gphoto2 as gp ImportError: No module named 'sh'
Any insight is much appreciated (including any better way to go about a time lapse capture!)
Thanks!
Reply
#2
I assume you mean this module?

How to install
pip install sh
Recommended Tutorials:
Reply
#3
(Jun-25-2019, 03:18 PM)metulburr Wrote: I assume you mean this module? How to install
pip install sh
thanks for your help! I tried that before and nothing changed! it ended up going through after doing

sudo pip3 install sh 


I'm not sure yet what the main difference is here.

Now I'm getting:
Error:
Traceback (most recent call last); File "earth_test_4.py", line 15, in <module> folder_name = shot_date + picID NameError: name 'picID' is not defined"
any idea what I did incorrectly here?

---edit: I found a simple typo! My mistake
Reply
#4
so the issue is resolved?
Recommended Tutorials:
Reply
#5
(Jun-25-2019, 04:30 PM)metulburr Wrote: so the issue is resolved?

Yes, thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 876 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 23,735 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,564 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,439 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,505 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,336 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 1,038 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 9,066 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,010 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,842 Oct-20-2022, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020