Is PIL supposed to be available or not?

I primarily use Linux. Using Blender on Linux (installed from my distro’s repositories), I can go to the console and import PIL no problem.

If I hop over to Windows and try to do the same thing (Blender downloaded from Blender.org), I’m hit with “No module named PIL”.

My understanding (which might be wrong) is that Blender includes its own Python install. As such… should this not be consistent? Regardless of where you got Blender?

Can someone educate me?

I think the only python libraries that are bundled in the official releases are numpy and requests.

So I’m guessing that your linux dist are not bundling python and instead uses the system wide install, which you can choose to do when compiling blender.

1 Like

That makes sense. I didn’t know that was an option when you compile Blender. Thank you for the explanation.

1 Like

You can check which module is actually used with e.g. this:

# Official binaries
# Numpy is included, note the path to numpy/__init__.py
melis@juggle 12:14:~/software/blender-2.92.0-linux64$ ./blender -b --python-expr 'import numpy; print(numpy.__file__)'
Blender 2.92.0 (hash 02948a2cab44 built 2021-02-25 09:31:37)
Read prefs: /home/melis/.config/blender/2.92/config/userpref.blend
loading in background
/home/melis/software/blender-2.92.0-linux64/2.92/python/lib/python3.7/site-packages/numpy/__init__.py

Blender quit

# PIL is not included in the official Blender distro and cannot be found
melis@juggle 12:14:~/software/blender-2.92.0-linux64$ ./blender -b --python-expr 'import PIL; print(PIL.__file__)'
Blender 2.92.0 (hash 02948a2cab44 built 2021-02-25 09:31:37)
Read prefs: /home/melis/.config/blender/2.92/config/userpref.blend
loading in background
<bpy_struct, WindowManager("WinMan") at 0x7f0f4cb05c08>
Error: Python: Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'PIL'

My Arch linux blender package can find all system-wide packages, e.g.:

# PIL can now be found
melis@juggle 12:17:~$ /usr/bin/blender -b --python-expr 'import PIL; print(PIL.__file__)'
Blender 2.92.0 (hash 02948a2cab44 built 2021-04-25 11:39:34)
Read prefs: /home/melis/.config/blender/2.92/config/userpref.blend
loading in background
<bpy_struct, WindowManager("WinMan") at 0x7febdcbd5008>
/usr/lib/python3.9/site-packages/PIL/__init__.py

Blender quit

# Even system-wide numpy is used
melis@juggle 12:17:~$ /usr/bin/blender -b --python-expr 'import numpy; print(numpy.__file__)'
Blender 2.92.0 (hash 02948a2cab44 built 2021-04-25 11:39:34)
Read prefs: /home/melis/.config/blender/2.92/config/userpref.blend
loading in background
<bpy_struct, WindowManager("WinMan") at 0x7f1b911e3008>
/usr/lib/python3.9/site-packages/numpy/__init__.py

Blender quit

Even with the official binaries it’s possible to use sys.path to point to the right system-wide location:

melis@juggle 12:18:~/software/blender-2.92.0-linux64$ ./blender -b --python-expr 'import sys; sys.path.insert(0,"/usr/lib/python3.9/site-packages"); import PIL; print(PIL.__file__)'
Blender 2.92.0 (hash 02948a2cab44 built 2021-02-25 09:31:37)
Read prefs: /home/melis/.config/blender/2.92/config/userpref.blend
loading in background
<bpy_struct, WindowManager("WinMan") at 0x7f3bd65ebc08>
/usr/lib/python3.9/site-packages/PIL/__init__.py

Blender quit

However, this might open a can of worms in terms of version compatibility between Blender’s builtin Python interpreter and the system-wide one, especially for packages that contain compiled C code like numpy.

1 Like