@@ -134,3 +134,127 @@ The following environments come with a preinstalled version of [pngquant]:
134134 [ pngquant ] : https://pngquant.org/
135135 [ built-in optimize plugin ] : ../../plugins/optimize.md
136136 [ pngquant-winbuild ] : https://github.com/jibsen/pngquant-winbuild
137+
138+ ## Troubleshooting
139+
140+ ### Cairo library was not found
141+
142+ After following the installation guide above it may happen that you still get
143+ the following error:
144+
145+ ``` bash
146+ no library called " cairo-2" was found
147+ no library called " cairo" was found
148+ no library called " libcairo-2" was found
149+ cannot load library ' libcairo.so.2' : error 0x7e. Additionally, ctypes.util.find_library () did not manage to locate a library called ' libcairo.so.2'
150+ cannot load library ' libcairo.2.dylib' : error 0x7e. Additionally, ctypes.util.find_library () did not manage to locate a library called ' libcairo.2.dylib'
151+ cannot load library ' libcairo-2.dll' : error 0x7e. Additionally, ctypes.util.find_library () did not manage to locate a library called ' libcairo-2.dll'
152+ ```
153+
154+ This means that the [ ` cairosvg ` ] [ PyPi CairoSVG ] package was installed, but the
155+ underlying [ ` cairocffi ` ] [ PyPi CairoCFFI ] dependency couldn't [ find] [ cffi-dopen ]
156+ the installed library. Depending on the operating system the library lookup
157+ process is different:
158+
159+ !!! tip
160+ Before proceeding remember to fully restart any open Terminal windows, and
161+ their parent hosts like IDEs to reload any environmental variables, which
162+ were altered during the installation process. This might be the quick fix.
163+
164+ === ":material-apple: macOS"
165+
166+ On macOS the library lookup checks inside paths defined in [dyld][osx-dyld].
167+ Additionally each library `name` is checked in [three variants][find-library-macOS]
168+ with the `libname.dylib`, `name.dylib` and `name.framework/name` format.
169+
170+ [Homebrew] should set every needed variable to point at the installed
171+ library directory, but if that didn't happen, you can use the debug script
172+ below to see what paths are looked up.
173+
174+ A [known workaround][cffi-issue] is to add the Homebrew lib path directly
175+ before running MkDocs:
176+
177+ ```bash
178+ export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib
179+ ```
180+
181+ View source code of [cairo-lookup-macos.py]
182+
183+ ```bash title="Python Debug macOS Script"
184+ curl "https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-macos.py" | python -
185+ ```
186+
187+ === ":fontawesome-brands-windows: Windows"
188+
189+ On Windows the library lookup checks inside the paths defined in the
190+ environmental `PATH` variable. Additionally each library `name` is checked
191+ in [two variants][find-library-Windows] with the `name` and `name.dll` format.
192+
193+ The default installation path of [GTK runtime] is:
194+
195+ ```powershell
196+ C:\Program Files\GTK3-Runtime Win64
197+ ```
198+
199+ and the libraries are in the `<INSTALL-DIR>\lib` directory. Use the debug
200+ script below to check if the path is included. If it isn't then:
201+
202+ 1. Press ++windows+r++.
203+ 2. Run the `SystemPropertiesAdvanced` applet.
204+ 3. Select "Environmental Variables" at the bottom.
205+ 4. Add the whole path to the `lib` directory to your `Path` variable.
206+ 5. Click OK on all open windows to apply changes.
207+ 6. Fully restart any open Terminal windows and their parent hosts like IDEs.
208+
209+ ```powershell title="You can also list paths using PowerShell"
210+ $env:Path -split ';'
211+ ```
212+
213+ View source code of [cairo-lookup-windows.py]
214+
215+ ```powershell title="PowerShell - Python Debug Windows Script"
216+ (Invoke-WebRequest "https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-windows.py").Content | python -
217+ ```
218+
219+ === ":material-linux: Linux"
220+
221+ On Linux the library lookup can [differ greatly][find-library-Linux] and is
222+ dependant from the installed distribution. For tested Ubuntu and Manjaro
223+ systems Python runs shell commands to check which libraries are available in
224+ [`ldconfig`][ubuntu-ldconfig], in the [`gcc`][ubuntu-gcc]/`cc` compiler, and
225+ in [`ld`][ubuntu-ld].
226+
227+ You can extend the `LD_LIBRARY_PATH` environmental variable with an absolute
228+ path to a library directory containing `libcairo.so` etc. Run this directly
229+ before MkDocs:
230+
231+ ```bash
232+ export LD_LIBRARY_PATH=/absolute/path/to/lib:$LD_LIBRARY_PATH
233+ ```
234+
235+ You can also modify the `/etc/ld.so.conf` file.
236+
237+ The Python script below shows, which function is being run to find installed
238+ libraries. You can check the source to find out what specific commands are
239+ executed on your system during library lookup.
240+
241+ View source code of [cairo-lookup-linux.py]
242+
243+ ```bash title="Python Debug Linux Script"
244+ curl "https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-linux.py" | python -
245+ ```
246+
247+ [ PyPi CairoSVG ] : https://pypi.org/project/CairoSVG
248+ [ PyPi CairoCFFI ] : https://pypi.org/project/CairoCFFI
249+ [ osx-dyld ] : https://www.unix.com/man-page/osx/1/dyld/
250+ [ ubuntu-ldconfig ] : https://manpages.ubuntu.com/manpages/focal/en/man8/ldconfig.8.html
251+ [ ubuntu-ld ] : https://manpages.ubuntu.com/manpages/xenial/man1/ld.1.html
252+ [ ubuntu-gcc ] : https://manpages.ubuntu.com/manpages/trusty/man1/gcc.1.html
253+ [ cffi-issue ] : https://github.com/squidfunk/mkdocs-material/issues/5121
254+ [ cffi-dopen ] : https://github.com/Kozea/cairocffi/blob/f1984d644bbc462ef0ec33b97782cf05733d7b53/cairocffi/__init__.py#L24-L49
255+ [ find-library-macOS ] : https://github.com/python/cpython/blob/4d58a1d8fb27048c11bcbda3da1bebf78f979335/Lib/ctypes/util.py#L70-L81
256+ [ find-library-Windows ] : https://github.com/python/cpython/blob/4d58a1d8fb27048c11bcbda3da1bebf78f979335/Lib/ctypes/util.py#L59-L67
257+ [ find-library-Linux ] : https://github.com/python/cpython/blob/4d58a1d8fb27048c11bcbda3da1bebf78f979335/Lib/ctypes/util.py#L92
258+ [ cairo-lookup-macos.py ] : https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-macos.py
259+ [ cairo-lookup-windows.py ] : https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-windows.py
260+ [ cairo-lookup-linux.py ] : https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/includes/debug/cairo-lookup-linux.py
0 commit comments