HOME/Articles/

pil example pil (snippet)

Article Outline

Python pil example 'pil'

Functions in program:

  • def ensure_PIL():

python pil

Python pil example: pil

def ensure_PIL():
    try:
        import PIL

    except ModuleNotFoundError:
        print("Installing PIL")

        import subprocess
        r = subprocess.run(["pip", "install", "Pillow"])

        if r.returncode == 0:
            import PIL

        else:
            print("PIL could not be installed")