From 1b882e0f11959b19b8c1021b2c6aae0250f4bbd8 Mon Sep 17 00:00:00 2001 From: TSC <112517630+LucianoCirino@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:25:34 -0500 Subject: [PATCH] Auto Package Installer Changes Auto required package isntaller package now uses the "requirements.txt" folder as reference for what packages to install. Packages are also now installed straight to the ComfyUI's python embedded site-packages folder via relative pathing. Updated messages to be cleaner on console aswell. --- tsc_utils.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/tsc_utils.py b/tsc_utils.py index 9da54f3..01f0afd 100644 --- a/tsc_utils.py +++ b/tsc_utils.py @@ -460,24 +460,35 @@ def global_preview_method(): return args.preview_method #----------------------------------------------------------------------------------------------------------------------- -# Auto install Efficiency Nodes Python packages +# Auto install Efficiency Nodes Python package dependencies import subprocess -def install_packages(required_packages): - installed_packages = packages(versions=False) +# Note: Auto installer targets ComfyUI's python_embedded folder + +def install_packages(my_dir): + # Compute path to the target site-packages + target_dir = os.path.abspath(os.path.join(my_dir, '..', '..', '..', 'python_embeded', 'Lib', 'site-packages')) + embedded_python_exe = os.path.abspath(os.path.join(my_dir, '..', '..', '..', 'python_embeded', 'python.exe')) + + # Load packages from requirements.txt + with open(os.path.join(my_dir, 'requirements.txt'), 'r') as f: + required_packages = [line.strip() for line in f if line.strip()] + + installed_packages = packages(embedded_python_exe, versions=False) for pkg in required_packages: if pkg not in installed_packages: - print(f"\033[32mEfficiency Nodes:\033[0m Installing {pkg}...") - subprocess.check_call([sys.executable, '-m', 'pip', 'install', pkg]) - print(f"\033[32mEfficiency Nodes:\033[0m Installed {pkg}!") + print(f"\033[32mEfficiency Nodes:\033[0m Installing required package '{pkg}'...", end='', flush=True) + subprocess.check_call(['pip', 'install', pkg, '--target=' + target_dir, '--no-warn-script-location', + '--disable-pip-version-check'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + print(f"\r\033[32mEfficiency Nodes:\033[0m Installing required package '{pkg}'... Installed!", flush=True) -def packages(versions=False): +def packages(python_exe, versions=False): + # Get packages of the embedded Python environment return [(r.decode().split('==')[0] if not versions else r.decode()) for r in - subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']).split()] + subprocess.check_output([python_exe, '-m', 'pip', 'freeze']).split()] -# Packages to install -required_packages = ['simpleeval', 'websockets'] -install_packages(required_packages) +# Install missing packages +install_packages(my_dir) #----------------------------------------------------------------------------------------------------------------------- # Auto install efficiency nodes web extension '\js\efficiency_nodes.js' to 'ComfyUI\web\extensions'