If you want to randomly chose an image to train, you do not need to store the path in a csv file - you could do the following -
os.chdir('absolute path to images')
images = os.listdir()
image = random.choice(images) #return image name. Now load this image

Coming to your code, the variable path Is not initialized. Could you share the code?