luispedro / mahotas

Computer Vision in Python
https://mahotas.rtfd.io
Other
844 stars 148 forks source link

Improve loading of FreeImage.dll #14

Closed cgohlke closed 12 years ago

cgohlke commented 12 years ago

This PR addresses potential issues with loading the FreeImage.dll on Windows, especially in frozen distributions.

ctypes.util.find_library does not find DLLs that are placed next to freeimage.py or sys.executable, the most common places for binary and frozen distributions to place FreeImage.dll. Currently FreeImage.dll is preferably loaded from other places in the os.environ['PATH'] list. A FreeImage.dll located next to sys.executable is never loaded AFAICT. This makes binary/frozen distributions that ship with tested FreeImage.dll more unreliable.

With the proposed fix, FreeImage.dll is first loaded from the directory where freeimage.py is located, and if that fails loaded from one of the Windows DLL search path, which includes the sys.executable directory at the top of the list.

The code is adapted from https://github.com/PyTables/PyTables/pull/178 to 180

Tested on Windows, Python 2.6 to 3.2 only. This should be tested on other platforms.

luispedro commented 12 years ago

On my system, it passes all unit tests.

Thanks for all your work.