get cairosvg working in windows

Related searches

Trying to get this code working:

import cairosvg
import os

path = "D:/PyProjects/Bla/Temp"
os.chdir(path)

cairosvg.svg2pdf(url='Pic.svg', write_to='image.pdf')

but get errors along similar to this post:

Traceback (most recent call last):
  File "D:/work/lean_python/pdf/other.py", line 2, in <module>
    import cairosvg
  File "D:\env_python352\lib\site-packages\cairosvg\__init__.py", line 29, in <module>
    from . import surface
  File "D:\env_python352\lib\site-packages\cairosvg\surface.py", line 24, in <module>
    import cairocffi as cairo
  File "D:\env_python352\lib\site-packages\cairocffi\__init__.py", line 46, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "D:\env_python352\lib\site-packages\cairocffi\__init__.py", line 43, in dlopen
    raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2

The post mentions:

CairoSVG (the python library and bindings) needs Cairo (The C library, part of GTK+) to run. It appears you don't have it an it's headers installed on your system.

So I followed step 1 - 5 described here. I now have cairo header files in:

C:\msys64\mingw64\include\cairo

I also installed pycairo recommended by another source:

pip install pycairo-1.15.2-cp36-cp36m-win_amd64.whl

I still get the above errors. Any ideas?


I just do not get cairosvg to work. I found an alternative way to transform an svg into a png using the svglib package.

from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF, renderPM
import os

path = "D:/Bla/Temp"
os.chdir(path)

drawing = svg2rlg("Pic.svg")
renderPM.drawToFile(drawing, "Pic.png")

CairoSVG, CairoSVG. Convert your SVG files to PDF and PNG. a Python 3.5+ library;; known to work at least on Linux, OS X, and Windows;; based pip3 install cairosvg. What is CairoSVG? CairoSVG is a SVG 1.1 to PNG, PDF, PS and SVG converter. It provides both a command-line interface and Python 3.5+ library, for Unix-like operating systems (at least Linux and macOS) and Windows. It is a free software, distributed under LGPLv3. CairoSVG is written in Python and based on the famous 2D graphics library called Cairo.


Please check the path of libcairo-2.dll with the ctypes.util. In my case, It was a directory of old software called Graphviz.

python
>>> import ctypes.util
>>> path = ctypes.util.find_library('libcairo-2')
>>> print(path)
C:\Program Files (x86)\Graphviz 2.28\bin\libcairo-2.dll

After uninstalling Graphviz.

python
>>> import ctypes.util
>>> path = ctypes.util.find_library('libcairo-2')
>>> print(path)
C:\msys64\mingw64\bin\libcairo-2.dll

Documentation, The current version of CairoSVG requires at least Python 3.5, it doesn't work with on Windows, you'll have to install Visual C++ compiler for Python and Cairo;� CairoSVG is a SVG 1.1 to PNG, PDF, PS and SVG converter. It provides both a command-line interface and Python 3.4+ library, for Unix-like operating systems (at least Linux and macOS) and Windows. It is a free software, distributed under LGPLv3. CairoSVG is written in Python and based on the famous 2D graphics library called Cairo.


Difficulty running/installing CairoSVG python package on any , I'm running a Windows 10 virtual environment with Anaconda. I'm using CairoSVG is available on PyPI, you can install it with pip: Older versions of CairoSVG (1.x) work with Python 2.x, but they're not supported anymore. conda install linux-64 v2.3.0; noarch v2.4.2; osx-64 v2.3.0; win-64 v2.3.0; To install this package with conda run one of the following: conda install -c conda-forge cairosvg


get cairosvg working in windows, Trying to get this code working: import cairosvg import os path = "D:/PyProjects/ Bla/Temp" os.chdir(path) cairosvg.svg2pdf(url='Pic.svg', write_to='image.pdf') but � CairoSVG is a SVG converter based on Cairo. It can export SVG files to PDF, PostScript and PNG files. For further information, please visit the CairoSVG Website.


get cairosvg working in windows, Trying to get this code working:import cairosvgimport ospath = "D:/PyProjects/Bla/ Temp"os.chdir(path)cairosvg.svg2pdf(url='Pic.svg',� CairoSVG 2.4.0 has been released! Fix aspect and position when resizing root SVG tag; Follow aspect and position hints when using forced output size; Version 2.3.1 April 18, 2019. CairoSVG 2.3.1 has been released! Fix relative paths on Windows; Version 2.3.0 February 8, 2019. CairoSVG 2.3.0 has been released! Drop Python 3.4 support


CairoSVG is a SVG converter based on Cairo. It can export SVG files to PDF, PostScript and PNG files. For further information, please visit the CairoSVG Website.