0

I want to do

from PIL import Image

inside a Blender addon. But it throws this error at me:

ModuleNotFoundError: No module named 'PIL'

Thus I've tried to install Pillow via pip like this:

import subprocess
import ensurepip
ensurepip.bootstrap()
pybin = bpy.app.binary_path_python
subprocess.check_call([pybin, '-m', 'pip', 'install', 'Pillow'])

But this doesn't work, either.

What am I doing wrong? :)

Florian Ludewig
  • 253
  • 4
  • 16
  • Are you getting any error messages? What version of Blender are you using? – Robert Gützkow Mar 19 '20 at 17:17
  • Looks like I was mistaken and pip isn't included on the Linux release builds by default. Might have misunderstood Ray in T71420. In that case it should work with ensurepip, which you would only have to run once. Does it at least find pip after running ensurepip? – Robert Gützkow Mar 19 '20 at 20:48
  • ensurepip changes nothing. But it seems that pip is included in the snap version of Blender. But the import error that it can't find PIL persists – Florian Ludewig Mar 20 '20 at 07:07
  • Again I forgot to tag you @RobertGützkow – Florian Ludewig Mar 20 '20 at 11:55
  • ensurepip.boostrap() and installing the package through subprocess works fine for me. Do you really not get any error message from ensurepip? – Robert Gützkow Mar 20 '20 at 19:27
  • In a current version of Blender I could produce one particular problem. When ensurepip.bootstrap() is used followed by a pip install through subprocess, it fails to find a temp directory. This issue occurs on Linux and Windows. – Robert Gützkow Mar 27 '20 at 18:49
  • See my answer here. You need to remove the environment variable PIP_REQ_TRACKER if you directly install a package with pip after running ensurepip. – Robert Gützkow Apr 11 '20 at 13:29
  • @RobertGützkow I can't try it right now, but it seems really promising, thank you! – Florian Ludewig Apr 11 '20 at 13:41

1 Answers1

-1

I finally had to copy my PIL package from C:\Program Files\Python37\Lib\site-packages\ and moved it into the Blender Foundation\Blender\2.8.2\python\lib\site-packages and everything started working fine.

Dr Tyrell
  • 309
  • 1
  • 4
  • 14
  • 3
    That's the case because of the modification that you made to your Blender installation (see your other question). A clean and working installation of Blender comes with ensurepip, which allows to install pip, that can then install Pillow/PIL. The issue here is most likely that running ensurepip.bootstrap() sets an environment variable that makes a subsequent attempt to install a package with pip fail, because it tries to access a non-existent temp directory. This can be solved by removing the environment variable PIP_REQ_TRACKER. – Robert Gützkow Apr 11 '20 at 13:46