'Python - Import "PIL" could not be resolved from source, reportMissingModuleSource

I have this code

from PIL import Image
import os

directory = r'C:\Users\Filip\Desktop\turbos'
c=1
for filename in os.listdir(directory):
    if filename.endswith(".png"):
        im = Image.open(filename)
        name='turbo'+str(c)+'.jpeg'
        rgb_im = im.convert('RGB')
        rgb_im.save(name)
        c+=1
        print(os.path.join(directory, filename))
        continue
    else:
        continue

When I try to run the script in VSCode,I get this error.

" Import "PIL" could not be resolved from source "

I've ran the following in the terminal

pip uninstall PIL

python -m pip install --upgrade pip

python -m pip install --upgrade Pillow

I run these but then I still get that error when I try to run my script. What am I doing wrong?



Solution 1:[1]

two things first you need to check if you are using python3(pip3 install pillow) or not. Second you have to add it to your PATH in system variables in control panel.

Solution 2:[2]

Instead of doing pip install PIL do pip install Pillow

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yahya.k
Solution 2 Anurag Singh