From 1965b74fc9ff104147c3077a288580a3c6da84dd Mon Sep 17 00:00:00 2001 From: Roeland Schoukens Date: Wed, 25 Sep 2024 14:25:58 +1200 Subject: [PATCH] Respect MAGICK_HOME on Windows - Don't read Windows registry if MAGICK_HOME was set, keep the original value of the environment variable. - It now seems to be enough to only add the path to the main DLL to PATH. This is also what the ImageMagick installer does if you ask it to add ImageMagick to PATH. --- wand/api.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/wand/api.py b/wand/api.py index 2fcf4ddd..ecab1473 100644 --- a/wand/api.py +++ b/wand/api.py @@ -46,22 +46,17 @@ def library_paths(): magick_home = os.environ.get('MAGICK_HOME') magick_suffix = os.environ.get('WAND_MAGICK_LIBRARY_SUFFIX') - if system == 'Windows': - # ImageMagick installers normally install coder and filter DLLs in - # subfolders, we need to add those folders to PATH, otherwise loading - # the DLL later will fail. + if system == 'Windows' and magick_home is None: try: + # Try to read ImageMagick location from registry. + # This is necessary if the user did not add the ImageMagick directory + # to PATH. with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\ImageMagick\Current") as reg_key: libPath = winreg.QueryValueEx(reg_key, "LibPath") - coderPath = winreg.QueryValueEx(reg_key, "CoderModulesPath") - filterPath = winreg.QueryValueEx(reg_key, "FilterModulesPath") magick_home = libPath[0] - os.environ['PATH'] += str((';' + libPath[0] + ";" + - coderPath[0] + ";" + filterPath[0])) + os.environ['PATH'] += ';' + str(magick_home) except OSError: - # otherwise use MAGICK_HOME, and we assume the coder and - # filter DLLs are in the same directory pass def magick_path(path):