Unexpected token error for cv2 library Pavlovia

Hi, I know there are a lot of topics with this title. Sorry to add another, but I have not found a solution to my problem yet.
I am doing a picture description experiment where I record the participants’ videos and voices and save them as my output. To record and save videos, I used a code that imports the cv2 library. I used code because the video component in the builder was crashing my experiment, and I read that code would run the video component faster. However, now my experiment crashes while initializing the experiment. Is there a way to translate my python script to java? Or do you have any alternative suggestions? I also tried importing a set of routines maintained by Thomas Pronk, but it did not work.
Here is my code:
Begin Experiment:

import cv2  # this is the OpenCV library for computer vision
fourcc = cv2.VideoWriter_fourcc(*'XVID')
#out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,  480))
out = cv2.VideoWriter(expInfo['participant'] + '_output.avi', fourcc, 20.0, (640,  480))
webCam = cv2.VideoCapture(0)  # connect to the zeroth video camera

Each Frame:

returnVal, frame = webCam.read()
thisMovieFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)/255.0