diff --git a/src/robofish/io/file.py b/src/robofish/io/file.py
index e5bb2b1e9092d371b20583f5da87770fb3301ba5..0b5c4f169ff3c494370541271532b16d7ca9b3a4 100644
--- a/src/robofish/io/file.py
+++ b/src/robofish/io/file.py
@@ -906,8 +906,9 @@ class File(h5py.File):
             pbar = tqdm(range(n_frames))
 
         def update(frame):
-            pbar.update(1)
-            pbar.refresh()
+            if "pbar" in locals().keys():
+                pbar.update(1)
+                pbar.refresh()
 
             if frame < n_frames:
                 entity_poses = self.entity_poses_rad