From 64af288625463e752cce78a23078ea937248030b Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Tue, 10 Jun 2025 18:12:15 +0800 Subject: [PATCH] windows pyinstaller shim. the final loader will be moved into the packed directory later. --- koboldcpp.py | 14 +++++++++----- make_pyinstaller_shim.bat | 1 + tools/kcpplauncherhook.py | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 make_pyinstaller_shim.bat create mode 100644 tools/kcpplauncherhook.py diff --git a/koboldcpp.py b/koboldcpp.py index 988d140b4..6daf09386 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -660,15 +660,19 @@ def unpack_to_dir(destpath = ""): print(f"KoboldCpp will be extracted to {destpath}\nThis process may take several seconds to complete.") else: messagebox.showinfo("Unpack Starting", f"KoboldCpp will be extracted to {destpath}\nThis process may take several seconds to complete.") + pyds_dir = os.path.join(destpath, 'pyds') + os.makedirs(pyds_dir, exist_ok=True) for item in os.listdir(srcpath): s = os.path.join(srcpath, item) d = os.path.join(destpath, item) - if item.endswith('.pyd'): # Skip .pyd files - continue - if os.path.isdir(s): - shutil.copytree(s, d, False, None) - else: + if item.endswith('.pyd'): # relocate pyds files to subdirectory + d = os.path.join(pyds_dir, item) shutil.copy2(s, d) + else: + if os.path.isdir(s): + shutil.copytree(s, d, False, None) + else: + shutil.copy2(s, d) if cliunpack: print(f"KoboldCpp successfully extracted to {destpath}") else: diff --git a/make_pyinstaller_shim.bat b/make_pyinstaller_shim.bat new file mode 100644 index 000000000..2b1660ff0 --- /dev/null +++ b/make_pyinstaller_shim.bat @@ -0,0 +1 @@ +PyInstaller --onedir --noconfirm --clean --console --runtime-hook "./tools/kcpplauncherhook.py" --icon "./niko.ico" --version-file "./version.txt" "./koboldcpp.py" -n "koboldcpp-loader.exe" \ No newline at end of file diff --git a/tools/kcpplauncherhook.py b/tools/kcpplauncherhook.py new file mode 100644 index 000000000..9d51b1973 --- /dev/null +++ b/tools/kcpplauncherhook.py @@ -0,0 +1,10 @@ +import os +import sys + +# Determine the folder where the .pyd files will be located +pyd_subdir = os.path.join(sys._MEIPASS, 'pyds') + +# Add the subfolder to sys.path so Python can find the .pyd modules +print("Augmenting PYD directory...") +if os.path.isdir(pyd_subdir): + sys.path.insert(0, pyd_subdir) \ No newline at end of file