Bootstrap Chameleon Logo

Use 3rd Python package

Making good use of things

As our tools become more complex, we will definitely need various third-party Python libraries. The powerful features of these third-party libraries will also greatly enhance the functionality of our tools in the editor.

Common third-party libraries

  • PIL(Pillow)
  • imageio
  • numpy
  • matplotlib
  • scipy-learn
  • easyocr
  • skimage

Installing Third-Party Libraries

  1. Create a virtual environment

In the following example, we will use the Python in the UE engine to create a virtual environment to facilitate our subsequent installation of third-party libraries using pip:

virtualenv -p X:\UnrealEngine\Official\UE_5.1\Engine\Binaries\ThirdParty\Python3\Win64\python.exe ue_venv

Actually, you can use the locally installed Python as the interpreter for the virtual environment, but you need to ensure that the local Python version is consistent with the Python version in the UE engine.
Before Unreal 4.26 Preview 3, the Python version was 2.7.14
After (inclusive) Unreal 4.26 Preview 3, the Python version in UE4 is 3.7.7
Unreal 5 uses Python 3.7.9
In addition, you can use X:\UnrealEngine\Official\UE_5.1\Engine\Binaries\ThirdParty\Python3\Win64\python.exe --version to check the Python version in the UE engine.

  1. Activate the virtual environment

Enter the Scripts directory of the virtual environment, execute activate.bat; MacOS users execute source activate to activate the virtual environment.

  1. Install third-party libraries

In the virtual environment, use pip to install third-party libraries, such as installing Pillow:

pip install pillow

xport the third-party libraries that the current environment depends on to requirements.txt:

pip freeze > requirements.txt

You can use pip install -r requirements.txt to install from an existing requirements.txt file.

Creating a virtual environment in PyCharm and installing various third-party libraries through the interface is also possible. Also, pay attention to the consistency of the Python version.

Using Third-Party Library Paths in UE

In actual use, there are usually two situations:

  1. The Python tools in the project are used by multiple users in the project. In this case, we can copy the third-party libraries to the project directory <Your_Project>\TA\TAPython\Lib\site-packages, add them to version control, and distribute them with the project to each user. At the same time, add this directory to the Additional Path in the project's Project Settings.

  2. Independent developers with multiple UE projects locally. In this case, you can add the site-packages path from the virtual environment to the Additional Path in each project. This way, multiple UE projects can share the same set of third-party libraries.

'Additional Path' settings with 3rd-party package path included

Remember to ignore *.pyc files and pycache directories in your version control software.

File Structure