#π Python cannot import module in vs code
106 messages Β· Page 1 of 1 (latest)
@trim tangle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
video utils and init are in the utils folder
and main is just outside
and read_video is inside video_utils.py?
Have you saved the file? (I see that dot saying unsaved)
If it's not saved to disk, Python cannot find the code, because it doesn't technically exist yet.
just ctrl s all the files right?
Yup
Hmm okay i got out of that error, but now i have a different one
That's progress π
video is not loaded probably
yeah this is the problems of following just project tutorials
i write same to same code, but their understanding doesn't always match that of mine because updated libraries seem to sometimes give some different outputs
wait, that's the error from save_video()
@polar pond this is probably the video file right?
based on my experience, 9 out of 10 times yes.
py save_video()?
can you show the main.py and full error message?
because if you are following project tutorials, most of the time the function parts are usually correct unless there's a typo
this is where im at rn
okay
on line 6 of main.py, try print(video_frames).
Pretty old fashioned way I'm using - these days using debuggers are better but welp if it works it works ;p
indent it with the function?
yeap.
see, you are getting [] as the output, what would that mean?
what do you mean by getting [] as output? π€
oh
- all the lines previous to
print(video_frames)did work <-- doesn't mean it worked as you intended, but it did not give error anyways.
- for some reason, your video_frames are empty even after you read the video using
read_video()
hmm so i need to somehow fix read_video() and then main.py will work as i intend it to right?
in your method read_video(), it is said
if not ret:
break
``` this also means if `read_video()` gets nothing, it will return nothing instead of throwing error.
hmm... let's make that function more simple for your understanding
but to prevent confusion - no, it's not the problem on read_video()
hmm okay
def function(x):
list = []
while x > 1:
list.append(x)
x -= 1
if x == 2:
break
return list
Now I'm bad at examples, but hope this works
!e
def function(x):
list = []
while x > 1:
list.append(x)
x -= 1
if x == 2:
break
return list
print(function(5))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
[5, 4, 3]
So... basically same exact method, but got rid of those cv2 stuffs
you see, I've inputted 5, and inside the while loop, the x decrements, until x > 1, right?
Tell me anytime if you don't understand.
its more like it decrements until x == 2 right?
hence there is no 2 in the solution list
only watching while loop for now
hmm yeah i understand the decrement in the loop
but it is not printing 2 nor 1 because of the break
hmm yep
if you read the video through cap.read(), ret will be True. If not, it will be False.
and when its false, the loop will break right?
exactly
so what you can try is
add print("error loading video") before the break to see if it was triggered.
what's the problem with that though? shouldn't it still read through all of the frames in the video until the frames run out?
the problem is... it's not reading anything currently
and I suspect the reason to be you not having input_videos directory inside the project
i don't think it got triggered
huh
you gotta run the main.py haha
so you mean theres no video in the video_path directory?
yes, that's what I think.
but now you see the text printing
i dont think i see "error loading video"? π€
right before the []
indeed yes
so this is indeed just a video location error?
that's what I thought when I first saw the screenshot at least
because this photo didn't show any video folders - maybe cropped
but as I said
9 out of 10 times, video loading error
i just copied the code off the tutorial but im not sure where that video_path parameter refers to
in your actual project folder
you must have a folder named input_videos, and inside it, you must have a video file named 08fd33_4.avi
how did you figure that?
first off - I just watched this error too many times
i basically named the input_video folder as test data folder
let me rename it
and it has that file
second, I saw at the terminal that save_video() was being called
which means all precedented codes are 'syntax-wise' okay
thirdly, it said index out of range - which means it's reading something beyond one's limit
but in the save_video() you were simply using cv2.VideoWriter, which has no bug, so it has to do with video file itself.
fourth, you said you were following tutorial, which means the error will lie on the environment settings, not the actual code.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.