Getting error Could not import PIL.Image. The use of `load_img` requires PIL

I am getting this error after running this code:
p=Path(“C:/Users/Shreya/Desktop/machine learning/machine-learning-online-2018-master/Datasets/Images/images/”)

dirs = p.glob("*")

labels_dict = {“cat”:0,“dog”:1,“horse”:2,“human”:3}

image_data = []
labels = []

for folder_dirs in dirs:
#print(folder_name)
label = str(folder_dirs).split("\")[-1][:-1]
print(label)

for img_path in folder_dirs.glob("*.jpg"):
    img = image.load_img(img_path,target_size=(100,100))
    img_array = image.img_to_array(img)
    image_data.append(img_array)
    labels.append(labels_dict[label])

hey @shreyanarula3 ,
do you have PIL installed in your environment.
-> if yes ,
then first uninstall it and again install PIL so that you can get the latest version of it.
->if not ,
then kindly install it using command pip install pillow

I hope this will make your code working.

Already did that.
Even used the command pip install --upgrade tensorflow keras numpy pandas sklearn pillow

hey @shreyanarula3,
can you provide me with your code file.
or just reply with all your all import commands you have used.

and also , what is your keras and pillow version installed.

it worked. I just had to restart my laptop

Okay. Thats Nice.
If you haven’t marked this doubt as resolved ,then kindly get it done and do provide your valuable feedback to help us improve this platform.