Home > Back-end >  Python - Import "PIL" could not be resolved from source, reportMissingModuleSource
Python - Import "PIL" could not be resolved from source, reportMissingModuleSource

Time:02-23

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?

CodePudding user response:

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.

CodePudding user response:

Instead of doing pip install PIL do pip install Pillow

  • Related