Error no matching distribution found for pil

1. Purpose

1. Purpose

In this post, I would demo how to solve the following error when executing a python script with PIL included:

➜  myscripts git:(master) python3 watermark_batch.py image-20211015170843416.png
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:

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:

➜  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.

hello,
I am trying out PIL for the first time but I cannot add / download it.
Can someone help me with this?

I use pycharm for programming.

this is the code i tried:
import PIL
from PIL import Image, ImageTK

Posts: 7,842

Threads: 148

Joined: Sep 2016

Reputation:
572

rodink

Programmer named Tim


Posts: 5

Threads: 1

Joined: Jan 2020

Reputation:
0

Jan-16-2020, 02:59 PM
(This post was last modified: Jan-16-2020, 03:00 PM by rodink.)

(Jan-16-2020, 02:51 PM)buran Wrote: did you install Pillow?

i think i did
python -m pip install Pillow
Requirement already satisfied: Pillow in c:pythonpython38libsite-packages (7.0.0)

Posts: 7,842

Threads: 148

Joined: Sep 2016

Reputation:
572

Jan-16-2020, 03:00 PM
(This post was last modified: Jan-16-2020, 03:01 PM by buran.)

it’s Pillow, with capital P
using pip:
pip install Pillow

rodink

Programmer named Tim


Posts: 5

Threads: 1

Joined: Jan 2020

Reputation:
0

(Jan-16-2020, 03:00 PM)buran Wrote: it’s Pillow, with capital P
using pip:
pip install Pillow

Same result

pip install Pillow
Requirement already satisfied: Pillow in c:pythonpython38libsite-packages (7.0.0)

Posts: 7,842

Threads: 148

Joined: Sep 2016

Reputation:
572

Jan-16-2020, 03:10 PM
(This post was last modified: Jan-16-2020, 03:10 PM by buran.)

OK, it’s now installed and you should be able to import it (in your code in Pycharm or other IDE).
If you have multiple python installations, make sure that the correct one is set as interpreter in pycharm settings

rodink

Programmer named Tim


Posts: 5

Threads: 1

Joined: Jan 2020

Reputation:
0

(Jan-16-2020, 03:10 PM)buran Wrote: OK, it’s now installed and you should be able to import it (in your code in Pycharm or other IDE).
If you have multiple python installations, make sure that the correct one is set as interpreter in pycharm settings

Collecting PIL

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

it did not work

Posts: 7,842

Threads: 148

Joined: Sep 2016

Reputation:
572

Jan-16-2020, 03:22 PM
(This post was last modified: Jan-16-2020, 03:22 PM by buran.)

Hm, I don’t understand what you are doing:

(Jan-16-2020, 02:59 PM)rodink Wrote: i think i did
python -m pip install Pillow
Requirement already satisfied: Pillow in c:pythonpython38libsite-packages (7.0.0)

(Jan-16-2020, 03:04 PM)rodink Wrote: pip install Pillow
Requirement already satisfied: Pillow in c:pythonpython38libsite-packages (7.0.0)

Pillow is already installed for you python3.8 installation at c:pythonpython38

Now you should be able to do in Pycharm:

import PIL
from PIL import Image, ImageTK

given that python3.8 (c:pythonpython38) is set as default interpreter for the project


Note that Pillow is friendly fork of PIL and replaced it long time ago.

rodink

Programmer named Tim


Posts: 5

Threads: 1

Joined: Jan 2020

Reputation:
0

(Jan-16-2020, 03:22 PM)buran Wrote: Hm, I don’t understand what you are doing:

(Jan-16-2020, 02:59 PM)rodink Wrote: i think i did
python -m pip install Pillow
Requirement already satisfied: Pillow in c:pythonpython38libsite-packages (7.0.0)

(Jan-16-2020, 03:04 PM)rodink Wrote: pip install Pillow
Requirement already satisfied: Pillow in c:pythonpython38libsite-packages (7.0.0)

Pillow is already installed for you python3.8 installation at c:pythonpython38

Now you should be able to do in Pycharm:

import PIL
from PIL import Image, ImageTK

given that python3.8 (c:pythonpython38) is set as default interpreter for the project

i just put this in my code:

import PIL
from PIL import Image, ImageTK

it give me this error:

ModuleNotFoundError: No module named ‘PIL’

Posts: 7,842

Threads: 148

Joined: Sep 2016

Reputation:
572

Jan-16-2020, 03:41 PM
(This post was last modified: Jan-16-2020, 03:41 PM by buran.)

Read
https://www.jetbrains.com/help/pycharm/c…reter.html

and setup the interpreter for the project to be python3.8 with Pillow installed

Sometimes you get an error when you’re trying to install a Python package
using pip. It looks like this:

Could not find a version that satisfies the requirement (from versions:)
No matching distribution found for

Some probable reasons for this error are:

  1. PyPI server isn’t responding to your requests. It can happen either because
    the PyPI server is down or because it has blacklisted your IP address. This
    happened to me once when I was trying installing packages on a server.
    This can be fixed by using a proxy with pip. See the solution below.

  2. You’re running an older pip (especially on Mac). This can be fixed by
    upgrading your pip.
    See this post on Stack Overflow.
    Thanks to Anupam Jain who pointed this in a comment.

  3. The package you’re trying to install is not available for your Python version.

  4. The package is not available for your operating system. This is a rare case
    and only happens when the package is not pure-Python, i.e. it’s been
    partially written in C or Cython. Such a package needs to be compiled for
    every operating system (Windows/Mac/Linux) and architecture (32-bit/64-bit).
    Suppose a package has only been compiled for Windows 64-bit, then you’ll get
    this error if you try to install it on Windows 32-bit, or any other
    OS.

  5. The package is not present on PyPI server. In this case pip will not work. So
    you’ll have to download and install the package manually from Github or wherever
    it is available.

Solution¶

I had this issue because PyPI server had blacklisted the IP
of my hosting provider, the obvious solution was to make pip install via a proxy.

But to see if that’s also the case with you, you can test it like this:

$ curl https://pypi.org

The requestors Network has been blacklisted due to excessive request volume. 
If you are a hosting customer, please contact your hosting company's support. 
If you are the hosting company, please contact infrastructure-staff@python.org to resolve

If you see the message similar to above, that means your IP has also been
blacklisted by https://pypi.org.

If you don’t see this message then the reason for the pip error could be that you’re using
an older version. See this post on Stack Overflow
for a solution.

Anyways, this can be fixed by using a proxy with pip.

Supplying a proxy address to pip is easy:

$ pip install -r requirements.txt --proxy address:port

Above, address and port are IP address and port of the proxy.

To find proxies, just search Google for proxy list.

Other things that I tried¶

These are some other things that I tried to get rid of this issue.
Although they didn’t work for me, but they might work for you.

  1. Changing DNS resolver of my server.
    This makes sense if your server’s DNS resolver can’t find PyPI servers.
  2. Reconfiguring SSL, reinstalling CA certificates.
    This makes sense if you don’t have updated CA certificates which are used by
    PyPI servers.
  3. Downloading packages using wget.
    This is an alternative way to install Python packages. Download them via wget
    and then install them using python setup.py install. In my case, the server was
    blacklisted by PyPI so I was getting a 403 Forbidden error.
  4. Downloading packages using curl.
    Alternative to wget. In my case I didn’t get a 403 error but rather it just
    created invalid tarball files, instead of actually downloading them.
  5. Downloading packages using git or hg.
    If your desired packages have git or hg repositories that you can clone, this
    is a good workaround.

Понравилась статья? Поделить с друзьями:
  • Error no matching distribution found for matplotlib
  • Error no match for operator operand types are std ostream
  • Error no valid items were selected must be joints effectors or nurbs curves
  • Error no main class specified intellij idea kotlin
  • Error no ups definitions found in ups conf