How to run Python libraries PIL and pillow in the Unreal Editor

Viewed 170

I am currently attempting to run a Python file inside of the Unreal Editor's scripting environment that imports and uses the pillow (PIL fork) library's Image module:

from PIL import Image

However in the Unreal Editor's log I am getting the below error message when I try to run this script:

LogPython: Error: ModuleNotFoundError: No module named 'PIL'

I already have pillow installed on my computer, however the Unreal Editor doesn't seem to have it installed in it's internal Python package.

Is there any way I can execute or install pillow into the Unreal Editor?

1 Answers

I would be curious to see others approaches but I've found that adding Pythons site-packages path to the PYTHONPATH at Unreal Startup to be the ideal approach.

In the Unreal Python Settings (Edit > Project Settings > Search Python) you have the option to add a script that executes at start up. It's here we append any paths needed in our Pipeline.

import sys

if __name == '__main__':
   sys.path.append("C:\\python37\\Lib\\site-packages")

Assuming you have PIL, or PySide2 or any other library pip installed then it should become available.

Related