Source code for cgl.plugins.unreal.setup.setup

import os
import logging
import subprocess
from pathlib import Path

from cgl.core.config.edit import edit_user_config
from cgl.core.config.query import AlchemyConfigManager

CFG = AlchemyConfigManager()


[docs] def setup_unreal(version="5.6"): """ Install Unreal Engine Python dependencies for a given UE version. Uses Unreal's embedded Python interpreter but installs packages into a writable versioned directory, e.g. C:/alc/ue_python/5_6. This avoids writing into Program Files and bypasses pip falling back into the user site-packages. """ # Normalize version: "5.6" → "5_6" v_major, v_minor = version.split(".") v_tag = f"{v_major}_{v_minor}" # Construct UE embedded Python path program_files = os.getenv("PROGRAMFILES") ue_python_path = ( Path(program_files) / f"Epic Games/UE_{version}/Engine/Binaries/ThirdParty/Python3/Win64/python.exe" ) ue_python_path = ue_python_path.resolve() print(f"UE Python: {ue_python_path}") if not ue_python_path.exists(): logging.error(f"Unreal Engine {version} not found at {ue_python_path}") return # Alchemy code root (where requirements file is kept) code_root = Path(CFG.get_code_root()).resolve() # Locate per-version requirements file requirements_path = ( code_root / "cgl" / "plugins" / "unreal" / "setup" / f"{v_tag}_requirements.txt" ) requirements_path = requirements_path.resolve() if not requirements_path.exists(): logging.error(f"Requirements file not found: {requirements_path}") return # Target directory for installing UE-python dependencies target_dir = Path(f"C:/alc/ue_python/{v_tag}") target_dir.mkdir(parents=True, exist_ok=True) # Build subprocess command preserving quotes & spaces cmd = [ str(ue_python_path), "-m", "pip", "install", "--no-warn-script-location", "--upgrade", f"--target={str(target_dir)}", "-r", str(requirements_path), ] print("\nRunning pip install:") print(" ".join(cmd), "\n") # Execute installation subprocess.run(cmd, shell=True) # Register engine setup in config edit_user_config(["software", f"UNREAL ENGINE {version}"], "Unreal Engine") print(f"Installed Unreal Python deps to: {target_dir}\n")
if __name__ == "__main__": setup_unreal(version="5.6")