diff --git a/cairocffi/__init__.py b/cairocffi/__init__.py index b9f4e46..5bbc544 100644 --- a/cairocffi/__init__.py +++ b/cairocffi/__init__.py @@ -9,7 +9,9 @@ """ +import os import sys +from contextlib import suppress from ctypes.util import find_library from . import constants @@ -21,6 +23,17 @@ version_info = (1, 17, 2) +# Python 3.8 no longer searches for DLLs in PATH, so we can add everything in +# CAIROCFFI_DLL_DIRECTORIES manually. Note that unlike PATH, add_dll_directory +# has no defined order, so if there are two cairo DLLs in PATH we might get a +# random one. +dll_directories = os.getenv('CAIROCFFI_DLL_DIRECTORIES') +if dll_directories and hasattr(os, 'add_dll_directory'): + for path in dll_directories.split(';'): + with suppress((OSError, FileNotFoundError)): + os.add_dll_directory(path) + + def dlopen(ffi, library_names, filenames): """Try various names for the same library, for different platforms.""" exceptions = [] diff --git a/docs/overview.rst b/docs/overview.rst index 6f87d72..cadfca9 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -60,9 +60,13 @@ If it fails to find it, you will see an exception like this:: Make sure cairo is correctly installed and available through your system’s usual mechanisms. + On Linux, the ``LD_LIBRARY_PATH`` environment variable can be used to indicate where to find shared libraries. +On Windows, you can put the folder where Cairo and other DLLs are installed in +the ``CAIROCFFI_DLL_DIRECTORIES`` environment variable. + .. _Pycairo: http://cairographics.org/pycairo/