Last active
December 7, 2022 13:23
-
-
Save FilipSivak/3d5b055c168fc6def04fa54e80d63355 to your computer and use it in GitHub Desktop.
Using pip install from Unreal Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unreal | |
import subprocess | |
import pkg_resources | |
from pathlib import Path | |
PYTHON_INTERPRETER_PATH = unreal.get_interpreter_executable_path() | |
assert Path(PYTHON_INTERPRETER_PATH).exists(), f"Python not found at '{PYTHON_INTERPRETER_PATH}'" | |
def pip_install(packages): | |
# dont show window | |
info = subprocess.STARTUPINFO() | |
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW | |
proc = subprocess.Popen( | |
[ | |
PYTHON_INTERPRETER_PATH, | |
'-m', 'pip', 'install', | |
'--no-warn-script-location', | |
*packages | |
], | |
startupinfo = info, | |
stdout = subprocess.PIPE, | |
stderr = subprocess.PIPE, | |
encoding = "utf-8" | |
) | |
while proc.poll() is None: | |
unreal.log(proc.stdout.readline().strip()) | |
unreal.log_warning(proc.stderr.readline().strip()) | |
return proc.poll() | |
# Put here your required python packages | |
required = {'tqdm'} | |
installed = {pkg.key for pkg in pkg_resources.working_set} | |
missing = required - installed | |
if len(missing) > 0: | |
pip_install(missing) | |
else: | |
unreal.log("All python requirements already satisfied") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment