Skip to content

How to resolve ERROR: Could not find a version that satisfies the requirement PIL (from versions: none) or ERROR: No matching distribution found for PIL when trying to execute python script with PIL included

Purpose

In this post, I will demonstrate how to resolve the following error when executing a Python script with PIL included:

Terminal window
Traceback (most recent call last):
File "/Users/bswen/work/python/myutils/myscripts/watermark_batch.py", line 1, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
myscripts git:(master) python3 --version
Python 3.9.7
myscripts git:(master) pip3 install PIL
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/opt/[email protected]/bin/python3.9 -m pip install --upgrade pip' command.
myscripts git:(master)

The core error message is:

Terminal window
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL

2. The environment

This is the python environment in my laptop:

image-20211030214256234

You can see that I am using python 3.7

3. The solution

The reason for this problem is:

  • Pillow has now been used instead of PIL
  • The most python version supported by PIL is 2.7,
  • And pillow version greater than 2.1 supports python2.6, 2.7 and 3.x,
  • The corresponding original import image is also replaced by from PIL import Image, pay attention to case.

So the solution is installing pillow instead of intalling PIL:

Terminal window
myscripts git:(master) pip3 install pillow
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting pillow
Downloading http://mirrors.aliyun.com/pypi/packages/32/25/32889d2b7c577b5a454dd12194b2ecb9d87d4b49c15c278dc99bc8ff5d2e/Pillow-8.4.0-cp39-cp39-macosx_10_10_x86_64.whl (3.0 MB)
|████████████████████████████████| 3.0 MB 8.2 MB/s
Installing collected packages: pillow
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Successfully installed pillow-8.4.0
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/opt/[email protected]/bin/python3.9 -m pip install --upgrade pip' command.
myscripts git:(master) python3 watermark_batch.py image-20211015170843416.png
start watermarking file image-20211030210011891.png
start watermarking file image-20211015181246892.png
start watermarking file image-20211015170843416.png
myscripts git:(master)

4. Summary

In this post, I demonstrated how to solve the ERROR: Could not find a version that satisfies the requirement PIL (from versions: none) or ERROR: No matching distribution found for PIL when trying to execute python script with PIL included. The key point is the ‘PIL’ library is replaced by ‘pillow’ library, we should use the latter to process images.

Final Words + More Resources

My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!