# ModuleNotFoundError: No module named 'PIL'

**URL:** <https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723>\
**Category:** Python Help\
**Created:** [October 5, 2022, 4:54pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723 "2022-10-05T16:54:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 5, 2022, 4:54pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/1 "2022-10-05T16:54:09Z")

</div>

```auto
#! /usr/bin/python3
# On 10/4/22 I installed version Python 3.10.7
# Does not work

# Traceback (most recent call last):
  # File "/home/andy/Python/png2jpg.py", line 10, in <module>
    # from PIL import Image
# ModuleNotFoundError: No module named 'PIL'

```

```auto
import math 

import os
import sys
from PIL import Image

if len(sys.argv) > 1:
    if os.path.exists(sys.argv[1]):
        im = Image.open(sys.argv[1])
        target_name = sys.argv[1] + ".jpg"
        rgb_im = im.convert('RGB')
        rgb_im.save(target_name)
        print("Saved as " + target_name)
    else:
        print(sys.argv[1] + " not found")
else:
    print("Usage: convert2jpg.py <file>")

```

I installed Pillow.

`pip3 install Pillow`

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [October 5, 2022, 8:17pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/2 "2022-10-05T20:17:29Z")

</div>

What version of Python are you using to run the script? You have to install Pillow for each and every version of Python you use.

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 5, 2022, 8:32pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/3 "2022-10-05T20:32:09Z")

</div>

Python 3.10.7

How do I install Pillow for this version?

---

<div class="post-metadata">

**Author:** ![vbrozik](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/vbrozik/32/7423_2.png) [@vbrozik](https://discuss.python.org/u/vbrozik)\
**Post date:** [October 5, 2022, 8:55pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/4 "2022-10-05T20:55:18Z")

</div>

If you run that Python using `python3` command then use the same command with option `-m pip` to invoke pip for that version. Example:

`python3 -m pip install Pillow`

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [October 5, 2022, 9:11pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/5 "2022-10-05T21:11:48Z")

</div>

That assumes that python3 is the same as python3.10, it may be some other version.

You may need to run `python3.10 -m pip install Pillow`.

`which python3` may also give you some useful information.

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 5, 2022, 9:23pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/6 "2022-10-05T21:23:51Z")

</div>

ERROR: Could not find a version that satisfies the requirement Pillow (from versions: none)  
ERROR: No matching distribution found for Pillow  
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.  
Could not fetch URL [https://pypi.org/simple/pip/:](https://pypi.org/simple/pip/:) There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=‘[pypi.org](http://pypi.org)’, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) - skipping  
WARNING: There was an error checking the latest version of pip.

which python3  
/usr/local/bin/python3

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 5, 2022, 9:53pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/7 "2022-10-05T21:53:09Z")

</div>

I have a second Ubuntu Mate installation that is 20.04.

My png2jpg script does work on it.

I did not need to install PIP either. 🙂

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 5, 2022, 11:45pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/8 "2022-10-05T23:45:54Z")

</div>

Which suggests that `/usr/local/bin/python3` does not have the `ssl`  
module. How was it installed?

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 6, 2022, 2:29am UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/9 "2022-10-06T02:29:07Z")

</div>

```auto
Which suggests that `/usr/local/bin/python3` does not have the `ssl`
module. How was it installed?

```

I do not remember how it was installed. I hope I can get it running in 18.04.

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 6, 2022, 5:09am UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/10 "2022-10-06T05:09:09Z")

</div>

What about `which -a python3`? If there are several, try each.

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 6, 2022, 8:01am UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/11 "2022-10-06T08:01:10Z")

</div>

I tried it and no luck.

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 6, 2022, 1:12pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/12 "2022-10-06T13:12:10Z")

</div>

I discovered this. Does it help in resolving my problem?

Modules are in /home/andy/.local/lib/python2.7/site-packages/

Thanks.

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 6, 2022, 9:52pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/13 "2022-10-06T21:52:14Z")

</div>

Where did this message come from?

These will be modules for Python 2.7, and you’re using Python 3.

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 6, 2022, 9:53pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/14 "2022-10-06T21:53:48Z")

</div>

What was the listing of installed `python3` commands?

For each such, does:

```
 python3 -m pip install Pillow

```

succeed or fail, replacing `python3` above with the full path to the  
various `python3` executables listed by `which -a python3`?

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 6, 2022, 11:35pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/15 "2022-10-06T23:35:17Z")

</div>

It just occurred to me that Ubuntu systems install some normal components of Python 3 as distinct packages, eg `python-tk` for the Tkinter modules.

Try installing `python3-openssl`, eg:

```
# apt-get install python3-openssl

```

and then see if pip’s behaviour improves.

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 7, 2022, 12:16am UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/16 "2022-10-07T00:16:52Z")

</div>

> [@cameron](#):
>
> ```auto
> apt-get install python3-openssl
> 
> ```

Thanks for your help. I installed it, but I get the same error.

I wish I could find someone running Ubuntu Mate 18.04 who is using Python.

This is a nice script I found that lets you paste snippets.  
It runs because it uses no modules.

```auto
#!/usr/bin/env python3
#
# /home/andy/.config/snippet_paste/ is where text to be inserted reside.
# Use Alt P to activate

import os
import subprocess

home = os.environ["HOME"]
directory = home+"/.config/snippet_paste"
if not os.path.exists(directory):
    os.mkdir(directory)
# create file list with snippets
files = [
    directory+"/"+item for item in os.listdir(directory) \
         if not item.endswith("~") and not item.startswith(".")
    ]
# create string list
strings = []
for file in files:
    with open(file) as src:
        strings.append(src.read())
# create list to display in option menu
list_items = ["manage snippets"]+[
    (str(i+1)+". "+strings[i].replace("\n", " ").replace\
     ('"', "'")[:20]+"..") for i in range(len(strings))
    ]
# define (zenity) option menu
test= 'zenity --list '+'"'+('" "')\
      .join(list_items)+'"'\
      +' --column="text fragments" --title="Paste snippets"'
# process user input
try:
    choice = subprocess.check_output(["/bin/bash", "-c", test]).decode("utf-8")
    if "manage snippets" in choice:
        subprocess.call(["seamonkey", directory])
    else:
        i = int(choice[:choice.find(".")])
        # copy the content of corresponding snippet
        copy = "xclip -in -selection c "+"'"+files[i-1]+"'"
        subprocess.call(["/bin/bash", "-c", copy])
        # paste into open frontmost file
        paste = "xdotool key Control_L+v"
        subprocess.Popen(["/bin/bash", "-c", paste])
except Exception:
    pass

```

Help me Obiwan Kenobi, you are my only hope. 🙂

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 7, 2022, 9:46pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/17 "2022-10-07T21:46:42Z")

</div>

> > [@cameron](#):
> >
> > ```auto
> > apt-get install python3-openssl
> > 
> > ```
> 
> Thanks for your help. I installed it, but I get the same error.

From _every_ `python3` executable? eg does:

```
 /usr/bin/python3 -m pip install Pillow

```

succeed or fail? A full transcript of the output would be helpful.

Ubuntu provides a `python3-pillow` package. Have you tried:

```
 apt-get install python3-pillow

```

> I wish I could find someone running Ubuntu Mate 18.04 who is using Python.

I’m running 21.04 here unfortunately, not 18.04. I do have an 18.04 box  
on the shelf I could set up again, and I suppose I could make a VM.

> This is a nice script I found that lets you paste snippets.  
> It runs because it uses no modules.

“os” and “subprocess” are modules, they just come presupplied. Normally  
“ssl” is also presupplied.

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 7, 2022, 9:47pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/18 "2022-10-07T21:47:18Z")

</div>

```auto
python3.6 -m pip install --upgrade pip

python3.6 -m pip install --upgrade Pillow 

#! /usr/bin/python3.6

# Use python3.6 [name of python script]
# Much help from ironfoot and karel
 
import os
import sys
from PIL import Image
 
if len(sys.argv) > 1:
    if os.path.exists(sys.argv[1]):
        im = Image.open(sys.argv[1])
        target_name = sys.argv[1] + ".jpg"
        rgb_im = im.convert('RGB')
        rgb_im.save(target_name)
        print("Saved as " + target_name)
    else:
        print(sys.argv[1] + " not found")
else:
    print("Usage: convert2jpg.py <file>")
    

```

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [October 8, 2022, 12:26am UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/19 "2022-10-08T00:26:50Z")

</div>

> ```auto
> python3.6 -m pip install --upgrade pip
> python3.6 -m pip install --upgrade Pillow
> 
> ```

Did these succeed? I don’t see a transcript eg shell prompt and  
resulting output.

Example here:

```
 [~/hg/css-ebooks(hg:ebooks)]fleet2*> /usr/local/bin/python3.8 -m pip install --upgrade 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
 Requirement already satisfied: Pillow in 
 /Users/cameron/Library/Python/3.8/lib/python/site-packages (8.3.1)
 Collecting Pillow
   Using cached Pillow-9.2.0-cp38-cp38-macosx_10_10_x86_64.whl (3.1 MB)
 Installing collected packages: Pillow
   Attempting uninstall: Pillow
     Found existing installation: Pillow 8.3.1
     Uninstalling Pillow-8.3.1:
       Successfully uninstalled Pillow-8.3.1
   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
 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-9.2.0
 WARNING: You are using pip version 21.2.4; however, version 22.2.2 is available.
 You should consider upgrading via the '/usr/local/opt/python@3.8/bin/python3.8 -m pip install --upgrade pip' command.

```

Ignore the deprecation warnings, they’re an artifact of the local  
environment.

> #! /usr/bin/python3.6

This will indeed run the script using `/usr/bin/python3.6` if you invoke  
the script directly as a command.

But you can run it with any Python interpret to test its behaviour with  
that interpreter, eg:

```
 /usr/bin/python3.6 your-script.py

```

Adjust to suit.

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![fixit7](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@fixit7](https://discuss.python.org/u/fixit7)\
**Post date:** [October 8, 2022, 5:06pm UTC](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723/20 "2022-10-08T17:06:40Z")

</div>

Yes, it succeeds.

```auto
python3.6 png2jpg.py Dust_Collector.png
Saved as Dust_Collector.png.jpg

```

Eventually I want to fix it so it outputs Dust\_Collector.jpg.

```auto
if len(sys.argv) > 1:
    if os.path.exists(sys.argv[1]):
        im = Image.open(sys.argv[1])
# Backspace 4 spaces and add .jpg    
  target_name = "sys.argv[1] - 4" + ".jpg"
        rgb_im = im.convert('RGB')
        rgb_im.save(target_name)
        print("Saved as " + target_name)
    else:
        print(sys.argv[1] + " not found")
else:
    print("Usage: convert2jpg.py <file>")

This does save it with .jpg but the file name is mangled.

```

Saved as sys.argv[1] - 4.jpg

[Next page](https://discuss.python.org/t/modulenotfounderror-no-module-named-pil/19723.md?page=2)
