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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
1
pip install sh
Recommended Tutorials:
Reply
#3
(Jun-25-2019, 03:18 PM)metulburr Wrote: I assume you mean this module? How to install
1
pip install sh
thanks for your help! I tried that before and nothing changed! it ended up going through after doing

1
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
  ModuleNotFoundError: No module named 'tkcalendar', Thonny, Windows 10 Edward_ 4 971 Apr-06-2025, 07:56 PM
Last Post: Edward_
  No module named 'importlib.metadata' EdVS 3 1,154 Jan-30-2025, 09:55 AM
Last Post: Larz60+
  ModuleNotFoundError: No module named 'athena_read' raman 2 1,349 Jul-01-2024, 07:52 AM
Last Post: Gribouillis
  no module named 'docx' when importing docx MaartenRo 1 5,881 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 31,430 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 10,409 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 4,622 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 3,979 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 3,322 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 2,521 Jul-09-2023, 11:24 AM
Last Post: yaoyao22

Forum Jump:

User Panel Messages

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